G_Waddell 131 Posting Whiz in Training

Drat! I was sure you could carry out a trim on a range...

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

hmmm, I think it is picking up space characters as values...
I may have the formula wrong it could be : Formula1: ="=APOIO!$A$":$A$100.TEXT.TRIM"

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

Try changing the formula part of your code to:
Formula1:="=Trim(APOIO!$A$2:$A$100)"

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 could you post the code you use to populate the lists?

G_Waddell 131 Posting Whiz in Training

Column of what? Datagrid?

G_Waddell 131 Posting Whiz in Training

Hi,

You need a variable to hold the current value and a second one to hold the "target" value...

The timer control fires depending on the interval you set for it in milliseconds.

dim iCount as integer 'Count or current value
dim iLimit as intger 'Limit value


sub Timer1_timer()
    iCount = iCount + 1
    if iCount >= iLimit then
        timer1.enabled = false
        Msgbox("Finished")
    End if
end sub


sub IncreaseLimit(byref Limit as Interval)
    iLimit = iLimit + Limit
end sub

As for what values to pass in, it depends how often you wish to check the values i.e. if you set the timer interval to 1000 (i.e. every second,) then inut your limit in seconds. 1 hour = 60 minutes = 3600 seconds

G_Waddell 131 Posting Whiz in Training

Hi,

Are you using a datasource to provide the dropdown values? Could the values be either NULL values or spaces?

G_Waddell 131 Posting Whiz in Training

I did, but as they were a newbie I though they may have accidently left it out when they copied it over, it must be there in the actual code or else how could they compile the code to get the error?

G_Waddell 131 Posting Whiz in Training

Sorry, you'll need to perform some sort of shell extension work to get into the windows shell.

Yes, the main example with the link I sent was on the Context menu, but I was hoping it would point you in the right direction, once you figure out how to get into the shell, there should be some examples out there showing you how to get into the status bar.

G_Waddell 131 Posting Whiz in Training

Hi,

did you specify an INSERT command for your DataAdapter (can't see it in your code sample)

G_Waddell 131 Posting Whiz in Training

Hi
I think you are looking to use textbox autocomplete which will be using your gird as it datasource and then you could select the matching row...

G_Waddell 131 Posting Whiz in Training

Ok the collection is in the settings.. What scope have you given the setting? Application or user?

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

Hi,

I don't see where you are removing items from your collection. I only see you adding and removing from your listbox.

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
Reading your example, this = that.theother(something) I would take that to mean variable = <Class or Namespace>.<Function>(Parameters)
where variable is some sort of variable of a type e.g. Integer, Object, Decimal, Boolean etc. The Class or Namespace contains a function that returns a value of the same type as your variable and you are passing parameters into it.

' <'> is a vb comment tag

'Example of a function  that returns an integer:
Public Function CountPersonVisits( ByRef PersonID as Integer) As Integer
' do whatever happens in here, for the sake of the example, 
'I declare a return Variable
dim MyReturn as Integer
'Processing happens here
'Returning our value
Return MyReturn
End Function
'Sub routines, Functions and Properties have acess scopes 
'Private(accessed only in the current class) 
'Public (Can be accessed by any class) 
'Friend (Can be accessed by members in any of the classes in the current assembly). 
'Protected (Can be accessed by methods in the current class 
'or in any class that inherits from this class)

'Declare a variable of type Integer
dim CountOfVisits as Integer
dim MyPersonID as integer = 1 'declared and set a value
'If the function occurs withing the same class 
CountOfVisits = CountPersonVisits(MyPersonID)

'If the Function occurs in a different class ( Function would have to be Public or Friend)
CountOfVisits = MyOtherClass.CountPersonVisits(MyPersonID)
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 want to select an item when the user selects the item and presses enter? But the user has just selected the item?
Looking at your code, it would appear you want the item to perform an action when the user hits enter and you may want other events to perform this action?
If this is the case, create a sub routine to perform the action(s) and in each of the sub routines that handle the events call it i.e.

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                ListBox1_PerformMyAction()
        End Select
End Sub


 Private sub  ListBox1_PerformMyAction()
     if ListBox1.SelectedItems.Count = 0 then
         Messagebox.Show("No Item Selected")
     Else
        '.... do whatever
     end if
 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
dim NewForm as new form2

NewForm.TextBox1.Text = "My Text"

NewForm.Show 
G_Waddell 131 Posting Whiz in Training
G_Waddell 131 Posting Whiz in Training

Hi,

I'd say you need to use the System.IO object to get the DirectoryInfo of any folders and the FileAttributes of any files selected.

Sub DirectorySelected (ByVal DirectoryPath)
Dim SubFolderCount, FileCount as integer
dim LastAccess as Date
Dim di As New DirectoryInfo(DirectoryPath)

FileCount = di.GetFiles().Length
SubFolderCount = di.GetDirectories().Length
LastAccess = di.LastAccessTime

End Sub
G_Waddell 131 Posting Whiz in Training

DataGridView1.Rows.Clear() will clear the rows for you.
If you want to completely clear everything from the grid you could then add DataGirdView1.Columns.Clear() to clear the columns as well.

G_Waddell 131 Posting Whiz in Training

@Learner010 - I know he was trying to write that he had read the book, but I was jokingly pointing out that due to him misspelling read as red, he could have also been saying he owned a book called Red as opposed to say the film version of Red... Given that he is only seven and is learning to write in two languages at the same time, (he goes to Gael Scoil so is learning primarily in Irish,) I think I'll forgive him this little slip up... :)

G_Waddell 131 Posting Whiz in Training

Hi,

I'd use an XMLReader to parse the XML and output in whatever format you wish:

Function PrintReport(byref XMLString as String) as String
dim OutPut as String
' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

'You want to get the XML in the "a" tag
reader.ReadToFollowing("a")
While reader.Read
    Select Case reader.NodeType
        Case XmlNodeType.Element
            OutPut +=  reader.Name &" = "
        Case XmlNodeType.Text
            OutPut +=  reader.Value & CrLf
        Case XmlNodeType.EndElement
               if reader.Name = "a" then
                   Exit While
               End if
    End Select
 End While
 Return OutPut
 End Function
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

Here is one I know causes confusion with non natives and youngsters learning to write:

Did I read the book? or have I just read the book?

My son wrote "I have red the book" last night - or maybe he was saying he has a book called Red....

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

You could try setting up a scheduled task to run a script to check if the conditions you are looking for are met and if so run your program.

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

I have another suggestion which could be easier for you.

Leave your main form open, but open each of the other forms using the showdialog method.

This will open each form as a modal dialog box in front of your main form and will prevent the user interacting with any other part of the application until the form is closed e.g.

sub Config_Click(byval sender as object, byval e as system.events)
dim frmConfig as new ConfigForm 
frmConfig.showDialog
end sub

Remember to add a way of closing your dialog form in the dialog forms code, you can also return a dialog result from the dialog form to the main form for processing as well e.g.

Public Sub ShowMyDialogBox()
    Dim testDialog As New Form2()

    ' Show testDialog as a modal dialog and determine if DialogResult = OK. 
    If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then 
        ' Read the contents of testDialog's TextBox.
        txtResult.Text = testDialog.TextBox1.Text
    Else
        txtResult.Text = "Cancelled" 
    End If
    testDialog.Dispose()
End Sub
G_Waddell 131 Posting Whiz in Training

Hi,
is the field Renter_ID in the database definately a string type? and not a numeric type? The reason I ask is that you say the error occurs when you fill your adaptor i.e. when you execute the query.

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 do you specify names for the textboxes i.e. something like this:

sub CreateTextboxes()
    dim i as integer =0
    dim txtbox as textbox
    do while i < 5
        txtbox =  new textbox
        txtbox.name = "TxtBox" & i
        '....
        i = i + 1
    wend
end sub

If so you should be able to specify by name

G_Waddell 131 Posting Whiz in Training

You could JOIN the tables using SQL Joins in your query...

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

Now lashing rain - normal service is being resumed...

G_Waddell 131 Posting Whiz in Training

Unseasonably sunny with a temperature of about 10 Degrees Centigrade in Ireland today

G_Waddell 131 Posting Whiz in Training

Book mark the following link www.connectionstrings.com It will explain and show all the different types of connections strings for you.

G_Waddell 131 Posting Whiz in Training

Hi,

Your query is soo complex that the connection string is probably timing out.

If you run that query in SQL (not through code but Management Studio,) how long does it take?

BTW you're missing a closing bracket.

G_Waddell 131 Posting Whiz in Training

No Worries - remember to mark as solved!