G_Waddell 131 Posting Whiz in Training

Hi,
The issue appears to be that your program can not initialise the connection to the database.

When you initialise the DRConnection class should you not be passing in your connection string? does the DRconnection class have a default string value? Do you have to call an open connection on the class or does it open as part of the new sub?

Maybe include some of your DRConnection source code?

G_Waddell 131 Posting Whiz in Training

Hi,

I don't see where you are setting your Connections connection string, you look to be passing in blank strings on the New DRConnection object (unless you are hiding the values your using for posting here.) so how does your DRConnection know what it is to connect to?

G_Waddell 131 Posting Whiz in Training

There is a great advert for toilet tissue here where the wife is helping the child draw a picture on paper and the husband pulls out his tablet and shows a graphics app to them saying "Karen" while shaking his head. Next clip, the couple are relaxing on the couche and she takes out a book and he takes out the tablet and again "Karen" while shaking his head and so on. The final scene is him in the toilet, he reaches for the toilet paper but it's finished, he shouts "Karen" and then sees his tablet being pushed under the door with a picture of a toilet roll on it. The tag line is paper has a future

Stuugie commented: I like it! +0
diafol commented: heh heh +0
G_Waddell 131 Posting Whiz in Training

My opinion is for certain tasks no. That being said I do have a Google tablet, my wife has an IPad and my son has a tablet too. One thing I can see a tablet being really handy for is instead of having to cart a load of textbooks into school, is that they should be able to down load them on to tablets and then bring in a single tablet.

I use my tablet for playing the odd game, watching netflix when travelling and surfing the web but to use it for anything else requires at least a keyboard and I have a laptop that has that built in, is more powerfull and nearly as portable.

As for desktop, I actually don't use one anymore we have one at home hooked up to the TV for if we want to watch netflix but that's about it. At work we all have laptops and docking stations so we can bring them to client sites if we need to.

I think one of the reason Windows Surface has struggled is they have tried to get the tablet to be more than a big smart phone and more like a laptop but have instead ended up with a product that is neither fish nor fowl with the result being people who want a machine for mainly entertainment buy a tablet, people who need it mainly for work buy a laptop and(if they need it,) a cheap tablet and poor old compromised Surface …

G_Waddell 131 Posting Whiz in Training

Hi,

If you are using a single dataset to hold the two tables you can also specify a DataRelation between them.

You can then get the child records of the parent record and vice versa.

Again you will still need to specify a parent primary key to child foreign key in your relationship though.

G_Waddell 131 Posting Whiz in Training

Hi
Does it highlight where the end of statement is expected?

Also do you handle if cmdLetter(index) is out of bounds?

G_Waddell 131 Posting Whiz in Training

You could also use e.handled=true just to add to the fire...

G_Waddell 131 Posting Whiz in Training

Remember to mark as solved....

G_Waddell 131 Posting Whiz in Training

Ah yes, thats caught me out a few times too!

G_Waddell 131 Posting Whiz in Training

Hi
You could put a in the function to ensure there are items in the listbox:

if lv2T1.Items.Count > 0 then
    currrentRow = lv2T1.Items.Count()-1
else
    exit sub        
end if

But as Minimalist states setting using this code will ALWAYS return you the last item in lv2T1. You may want to consider using the SelectedItem property to get the currently selected listitem.

G_Waddell 131 Posting Whiz in Training

Hi,
It is this line here:
currrentRow = lv2T1.Items.Count()
As Scudzilla said in VB you have zero based indexes but count will give you the count of items i.e. In your list item, if you have 25 items the count will return 25 but the index of the last item will actually be 24 (25-1 = 24) because the index is zero based. So you should change the line to:
currrentRow = lv2T1.Items.Count()-1

G_Waddell 131 Posting Whiz in Training
G_Waddell 131 Posting Whiz in Training

Hi
Create an array like so:

dim NumberToText as String = new String() {"zero", "one", "two", & _
"three", "four", "five", "six","seven", "eight", "nine"}

Then parse through your input one character at a time. Each character will be a number whose value corresponds to the index in the array where the conversion to string is stored:

Sub ShowAsString (byref InputText as String)
dim i as integer
dim sChar as string

for i = 0 to len(InputText)
    sChar = mid(InputText,i,1)
    If Not IsNumeric(sChar) then
        Messagebox.Show("Non Numeric Text entered")
        Exit Sub
    else
        'we know that we have a number and the string of that 
        ' number is in the array I assume you wish a line per number...
        MyOutPutLabel.Text  + =  NumbersToText(cint(sChar)) &vbcrlf
    end if
next
end sub
ddanbe commented: Nice code. +15
G_Waddell 131 Posting Whiz in Training

Hi,
Yes e.handled = true will stop the character.

G_Waddell 131 Posting Whiz in Training

Hi,
You would need to catch the cell using the DataGridViewCell Class and then the DataGridViewCell.Style Property to alter the style for that cell.

G_Waddell 131 Posting Whiz in Training

Wow! Thats a lot of Code to go through!

So I'll just go back to your question... You have a list of items and for each item you want to give total in stock and cash value.

OK there are two ways to do this:

1.Through a SQL query using SUM on the quantity and on the total and grouping by the other item fields : SELECT itemno, name, SUM(qty) As qty, price, SUM(Total) as Total FROM tblInventory GROUP BY itemno, name, price
2. Or as you said by looping through the records:

dim itemNo, CurrentItem as integer
dim ItemName as string
dim UnitPrice as decimal
dim TotalPrice as decimal
dim InStock, Qty as Integer
dim item as ListItem

CurrentItem = 0
'.....
'Modify your Query to sort by ItemNo
cls.sqlcmd.CommandText = "SELECT * FROM tblinventory Order By itemno"
'....
While cls.mydr.Read
    itemNo = cls.mydr("itemno")
    'Is this a new item?
    if itemNo <> CurrentItem then
        'Is this the first item?
        if CurrentItem <> 0 then
            'add previous item
            item = ListView3.Items.Add(CurrentItem)
            item.SubItems.Add(ItemName)
            item.SubItems.Add(InStock)
            item.SubItems.Add(UnitPrice)
            item.SubItems.Add(TotalPrice)
        end if
        'start again
        CurrentItem = itemNo
        ItemName = cls.mydr("itemname")
        InStock = 0
        TotalPrice = 0
     end if
     UnitPrice = cls.mydr("sellingprice")
     'Increment
     TotalPrice += UnitPrice
     Qty = cls.mydr("stocks")
     'Increment
     InStock += Qty
While End
'Get Last item...
if CurrentItem <> 0 then
    item = ListView3.Items.Add(CurrentItem)
    item.SubItems.Add(ItemName)
    item.SubItems.Add(InStock)
    item.SubItems.Add(UnitPrice)
    item.SubItems.Add(TotalPrice)
end if
G_Waddell 131 Posting Whiz in Training

Hi,
Do you have Excel installed on the machine? and if so, is it a version later than 2003? i.e. 2007 onwards to handle xlsx files? Or could something have changed the file associations?

Also you are opening the file by interop when you get the error not as a datasource. How are you referencing the Excel Application? By adding a reference to the Excel interop to the project? OR do you use late binding?

If you are using a reference, is it the correct one? i.e. pointing to a 2007 onwards version (v12) and not 2000, 2003 etc.. (you said it was based on an old project and both assemblies could be on the same machine, esp if you have installed a newer version over the older one...) If you you late binding then it should just use whichever version of excel is installed:

sub LateBindToExcel(byRef mypath as string)
'Example of Late binding - will use whichever version of excel is installed
dim xlapp as object = CreateObject("Excel.Application")
dim xlWorkbook as object = xlapp.WorkBooks.Open(path)
end sub
G_Waddell 131 Posting Whiz in Training

Hi,

You would run your insert on your table as normal passing the foreign key in as a value. For instance, to use your patient example, I want to record a visit by a patient with an ID of 1 to the doctor with an id of 2...
INSERT INTO tblVisits(VisitDate, patientID, doctorID, cost) Values('2014-01-27 14:30', 1, 2, 56.66)
Assuming there is also a tblDoctors, you have just inserted 2 foreign keys into the Visits table, patientID and doctorID, of course, you would have to have a doctor with an ID of 2 and a patient with an ID of 1...

G_Waddell 131 Posting Whiz in Training

Hi
Use the GetFileName function of Path:

Public Sub Scan()
    Dim ScanFolder as string
    ScanFolder = Directory.GetFiles("C:\examplefolder\", "." , SearchOption.AllDirectories.GetHashCode)
    for each dFile as String in ScanFolder
       ListBox1.Items.Add(System.IO.Path.GetFileName(dFile))
    next
End Sub

Also, you seem to be confusing Function with Sub. The simplest way to remember the difference is that in VB.Net, a Sub does something and a Function returns something (different from c# where it is all functions and the equivalent of sub is to return a null). i.e. I would create a Sub like this, Sub PopulateMyList(Byref MyList as ListBox) which I would code to only populate the Listbox, vs Function ReturnSelectedListItem (Byref ListBox) As ListBoxItem which I would code to return the selected listItem.

G_Waddell 131 Posting Whiz in Training

E.g if the file is located in Desktop for instance and the file name is test1.txt and the user browse to this file and select it to copy it to C:\example how to keep the same name test1.txt to the destination?

My example allows for this, here are the scenarios that my example handles:

  1. There is no file called "test1.txt" in the c:\example directory > copy over the file.
  2. There is a file called "test1.txt" in the c:\example directory and overwrite is true, overwrite the existing file with the "copying" file.
  3. There is a file called "test1.txt" in the c:\example directory and overwrite is false, copy the file as "test1(1).txt" to directory - or you could just flag up a messagebox and allow the user to specify a new name or quit.
G_Waddell 131 Posting Whiz in Training

Hi,
If you look at Interop it should help. Here is a tutorial

G_Waddell 131 Posting Whiz in Training

" The target file 'C:\example' is a directory, not a file."

you should do something like this:

Sub CopyFile(ByRef SourceFile as String, ByRef DestinationPath as string, Optional ByVal OverWrite as boolean = false)
dim FileName as String
dim ExtnPoint, Indx as integer
dim FilePath as string
if instrRev(SourceFile, "\") = 0 then
    MessageBox.show("Source File not complete path!")
    exit sub
else
    FileName = mid(SourceFile, instrRev(SourceFile, "\")+1)
end if

ExtnPoint = instrRev(FileName, ".")
if extnPoint = 0 then
    Messagebox.show ("The File String is invalid, there is no extension")
    exit sub
end if

if directory.Exists(DestinationPath) = False then
    'The Destination does not exist so create it
    directory.Create(DestinationPath)
    'Else - so what? we already have it
end if

if DestinationPath.EndsWith("\") = false then
    DestinationPath += "\" 'for appending the file to
end if

FilePath = DestnationPath & FileName
If File.Exists(FilePath) andAlso OverWrite = false then
    'if we don't wish to over write but wish to copy we can add an index to the file name
    'e.g. MyFile.txt  becomes MyFile(1).txt
    Indx=1
    While File.Exists(FilePath)
        FilePath = DestnationPath &Left(FileName, ExtnPoint-1) &"(" &Indx &")" &mid(FileName,ExtnPoint) 
        Indx+=1
    End While
end if

File.Copy(SourceFile, FilePath, OverWrite)

Messagebox.Show (Sourcefile & " Copied to " & FilePath)
End Sub
G_Waddell 131 Posting Whiz in Training

Still not sure what you are trying to achieve...
Do you mean you want to save the file in the directory?

This function would return the fullfilepath accounting for a file existing there already... The alternate would be to delete the existing file and save the new one.

function GetAvailableFilePath (byref Path as string, byref filename as String) As String
dim FullFileName as string
dim indx as integer = 1
dim Extn as integer = instrRev(filename, ".")
'ensure ends with \
if Right(Path,1) <> "\" then
    Path = Path &"\" 
end if

FullFileName = Path & filename
if Dir(FullFileName) <> "" Then
    'file Exists - assuming you wish to not overwrite:
    While Dir(FullFileName) <> ""
        'Keep incresing indx and adding to file name until we have no match
        FullFileName = Path & left(filename, extn-1) &"(" &indx &")" & mid(filename, extn)
        indx = indx+1
    wend
end if

Return FullFileName
end function
G_Waddell 131 Posting Whiz in Training

Hi Post some of your code and we can see where it is going wrong...

G_Waddell 131 Posting Whiz in Training

Hi,

You should check that Dir1.path is not equal to the App.path, are you having an issue with the code?

G_Waddell 131 Posting Whiz in Training

Santa or father Christmas represents St. Nicolas.. However the red coat comes from a Coca Cola advert... He used to be green

G_Waddell 131 Posting Whiz in Training

Christmas is all a matter of perspective, for instance, for me Christmas is December 25th but it does actually not fall on Christs birthday (As Diafol pointed out, it was a part of a p.r. campaign by the early Christian church in the west to put it on the same time as the pagan winter solstice festivals,) Eastern Christian churches celebrate Christmas in January for example. To me the holiday has morphed from a religon basis to that of mainly commercialism but the good thing about it is it is a time when family can all get together.

Interestingly after the reformation in Scotland, the church outlawed all festive behaviour and declared that the day should be one of penance, fasting and prayer so all the celebratory parts were moved to New Years (Hogmanay,) hence in Scotland we tend to go all out in celebration at Hogmanay (party starts on 31st and lasts until the 1st or 2nd).

G_Waddell 131 Posting Whiz in Training

The Porsche they were driving actually produces more power than an 1980's F1 car. Also, unlike most modern cars the GT4 is primarily built for the track not the street and as such has many of the features that most drivers take for granted traction control, Electronic stablity programs etc. have been removed or retuned for track use. The idea being that you can drive it to the track and race it but it shouldn't be your everyday car.

As for Paul Walker, didn't know the man but did see a series on Discovery channel with him in it about researching and conserving the Great White Shark where they brought the sharks up on a platform measured took readings and tagged them. He was involved not only as a sponsor and presenter but he was actually out in the boat helping the guys with the sharks

G_Waddell 131 Posting Whiz in Training

The good old local traditional Fish and Chip shop! But not too often!
When out after an evening drinking in Dublin (again not too often especially nowadays,) I tend to find myself in Zaytoon - it's an authentic kebab place everything is freshly made in store - they even have a guy rolling out dough and making pitta bread from scratch on a little oven thing!

G_Waddell 131 Posting Whiz in Training

We are the borg prepare to be assimilated...

G_Waddell 131 Posting Whiz in Training

Hi,

The Visual Basic versions are the pre .NET versions, the Visual Basic.NET versions are the versions of Visual Basic that run on the .NET framework.

Yes, there are differences between the two but if you have Visual Basic experience it should not be a huge "jump" to Visual Basic.NET.

In fact, the advantages to programming in VB.NET as opposed to VB will encourage you to move over as you become more familiar with VB.NET. For instance, in VB if you wanted a user to navigate to a file on the computer, you used to have to put a DriveListBox, a DirListBox and a FileListBox on your form and link them all in your code just to allow the user to select a file. In Visual Basic .NET you can now just use a single control, the OpenFileDialog this control opens a the standard Windows dialog and allows the user to select the file returning the filepath to you the only coding you worry about is processing the the filepath.

There should be plenty of resources out there to enable you to switch between the two, I'd recommend looking at the Microsoft Virtual Academy there free online courses there and I'd expect them to have a VB.NET one.

G_Waddell 131 Posting Whiz in Training

Hi,
What is MyRead? a Dataset? an adaptor? a Reader? some sort of data layer class?

I don't think you need the brackets around the information_schema.columns in your query, I tried it on SQL 2008 R2 and got a syntax error.

Your results will bring back a lot of data, if you only want column name and ordinal postion then try Select ordinal_Position, COLUMN_NAME FROM information_schema.columns WHERE (table_name ='Tb_test' ORDER BY ordinal_position

Try and put more steps or error handling in your code to identify what has happened and debugg with step by step i.e. Instead of just going straight into your loop see if you have results returned from your query first...

I'll use the example I gave you first modified with the query you used:

try
    dim cmd as new sqlcommand()
    cmd.connection = Myconnection
    cmd.CommandText = "SELECT Ordinal_Position, COLUMN_NAME FROM " & _
            "'Tb_test' ORDER BY Ordinal_Position"

    'Check connection is open 
    If MyConnection.State <> ConnectionState.Open then
        MyConnection.Open
    End if

    dim Reader as SqlDataReader = cmd.ExecuteReader

    'Check we get a result
    If Reader.HasRows then
        'we have rows
        While Reader.Read()
            txt2.Items.Add(Reader.GetSqlString(1))
        End While
    else
        'put in for debug purpose you can remove if not necessary
        Messagebox ("No Data Returned")
    end if
    Reader.close
Catch ex as Exception
    'unhandled errors
    messagebox.show(ex.message)
end try
G_Waddell 131 Posting Whiz in Training

Hi,
Try something like this:

Sub PopulateComboWithFieldNames(byref TableName as string, byref Combo as ComboBox, ByVal connection As SqlConnection)
 Dim cmd as new SQLCommand  
 Dim reader As SqlDataReader
 cmd.Connection = connection
 'I'd recommend using a stored Procedure with TableName passed as parameter
 'But for sake of clarity I'll do it like this...
 cmd.CommandText ="SELECT TOP 1 * FROM " & TableName

 if connection.state <> ConnectionState.Open then
     connection.open
 end if
reader = cmd.ExecuteReader()
 Dim schemaTable As DataTable = reader.GetSchemaTable()
 For Each row In schemaTable.Rows
        For Each column In schemaTable.Columns
         Combo.items.add(Column.ColumnName)
        Next           
    Next
    reader.Close()    

End Sub
G_Waddell 131 Posting Whiz in Training

Hi,

instead of Dim addr As String = "www.fedex.com/fedextrack/index.html?tracknumbers=" & strTID try Dim addr As String = "http://www.fedex.com/fedextrack/index.html?tracknumbers=" & strTID

G_Waddell 131 Posting Whiz in Training

Hi
If you are using Visual Studio 2010 or less then I've good news, you need to add a setup project to your solution and there is a setup project wizard to guide you through it. This setup project will deploy your program to the client in an executible. You should google set up and deployment in Visual Studio to find out which type of deployment project suits you.

Now for the bad news if you are using Visual Studio 2012 or 2013 Microsoft in an example of the type of stupidity they have been displaying lately have removed the setup and deployment projects from Visual Studio and now your are expected to use some third party tools - idiots, You've to develop a program for use on their operating system using their technologies but then go and get someone else to handle deployment for you.

G_Waddell 131 Posting Whiz in Training

Some operating systems (mostly older) use a 32 bit architecture and others use a 64 bit one. If you are unsure, select Any CPU on the compile options.. 64 bit architecture can make better use of memory and support a higher memory on the client machine I think a 32 bit is limited to using about 4 GB of RAM on the client (even if more is installed)

G_Waddell 131 Posting Whiz in Training

Hi,

It doesn't matter what version of Visual studio you use (for backwards compatibility,) your VB.Net project runs on the .Net framework and you can target earlier versions of the .NET framework in your project. e.g. if I select a .Net Framework version of 4.0 then as long as the OS of the computer I run it on has .Net Framework 4.0 installed then it will work. As far as I know Windows XP can have .Net 4.0 framework on it Not sure about 4.5 though. Also, note you need to watch out for 64 bit verses 32 bit (again you can select under project compile options)

G_Waddell 131 Posting Whiz in Training

Hi,

OK sorry, been busy at work.

Could you show me the code for the stored procedures?

I think you may have to modify them...

I think I have several ways of solving this but it really depends on how exactly you want this to work... which way suits best

  1. Feed the results of each proceedure into each other (if you are only looking at one item at a time this could be the way to go)

  2. If you have several items you want to display let SQL do the hard work and look at using views to generate the data.

  3. If you have several items you want to view at a time another possibility is to use a dataset and datatables with relationships to display the data. Not recommended if you are bringing back whole tables though.

  4. Something else I haven't though of yet...

G_Waddell 131 Posting Whiz in Training

KimberGariando see earlier postings mm gives minutes not month (MM)

G_Waddell 131 Posting Whiz in Training

Fair enough, As I said I was just curious and didn't mean any offense

G_Waddell 131 Posting Whiz in Training

OK lets take this slowly, to recap:
1. You want to return a value from a Stored Procedure
2. You want to assign this value to a variable that you then pass into another Stored Procedure or Select Statement

OR are we misunderstanding you?

Select Barcode, ItemCode, Get_itemCount From Product

You said Get_itemCount was the result of your first procedure can I ask what the select statement behind that procedure is? For instance, are you trying to do something like this get the barcode, itemcode and count of orders (or something similar,) from another table for each item?

If so you can do this with a select that uses a nested query:

SELECT itemcode, Barcode, ISNULL(Orders.Item_Count, 0) As Item_Count 
From Product
LEFT OUTER JOIN (
SELECT COUNT(*) As Item_Count, itemcode 
FROM OrdersTable 
GROUP BY itemcode
) As Orders ON Product.itemCode = Orders.itemcode
G_Waddell 131 Posting Whiz in Training

Hi,

No offense but your handle is Mr. Hacker and you want to hide programs from control panel etc....

I'm just slightly curious as to the purpose of this query.

G_Waddell 131 Posting Whiz in Training

Hi,

Also you need to specify that your command will use the connection...

G_Waddell 131 Posting Whiz in Training

Hi,

Try the IsNumeric to check if your input is numeric or not:

If Isnumeric(MyInput) then
    'Do something
else
    Msgbox("Non Numeric input detected")
end if
G_Waddell 131 Posting Whiz in Training
G_Waddell 131 Posting Whiz in Training

Dim myUpdateQuery As String = "Update Navire_Clients set equipage = 'Skipper' where Num = 10"
Should you not be changing this update query dynamically? Basically you have hardcoded in that the same record(s) will be updated I would expect to see something like this:
Dim myUpdateQuery As String = "Update Navire_Clients set equipage = '" &equipageValue &"' where Num = " &NumValue

Or if you are using parameters this:
Dim myUpdateQuery As String = "Update Navire_Clients set equipage = @equipage where Num = @Num"

G_Waddell 131 Posting Whiz in Training

Hi Xerohomicide,

Doesn't the .Tostring("d"), (short date) depend on your system locale settings?

G_Waddell 131 Posting Whiz in Training

Hi,
Just a note on using Mod, 0 Mod (any number) = 0 so you should also check your input is greater than 0 (unless of course, zero is an acceptable input)

G_Waddell 131 Posting Whiz in Training

hi,

Just to explain why you had results that appeared odd. Your month and Year columns were both varchar type when you sort these types, it will by default, sort the columns alphabetically... i.e April, August, December etc.
not January, February, March, April, May, June, July etc.

So if you put in a query that where month >= April and Month <=December I would only get records for April, August and December not April, May, June, July, August, September, October, November and December as it varchar will sort alphabetically.

As the others have said, you are better to use a date field this way you can sort by date

G_Waddell 131 Posting Whiz in Training

Hi,

Have you defined an Insert command for the Adaptor? Have you checked the syntax of the command by running it in your database?