Results 1 to 4 of 4

Thread: Passing Strings to function (SELF SOLVED DOH!)

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Passing Strings to function (SELF SOLVED DOH!)

    Hello All and thank you in advance.

    I am attempting to pass 3 string values to a function to automate filling a series of combo boxes on a form based off of information stored on several tables within a database..
    This is the Call:
    VB Code:
    1. FillForm("AcolumnName","AtableName","ComboBoxtoFill")

    The problem is the Underlined Item within code.
    I am not sure of how to translate the Comboboxname from a string to an object im assuming.

    I HAVE already attempted to pass the value as an object "
    .......,ByVal cboBox As Object.....
    But still recived an error at said location but no underline appeard on cbobox in code. So again im stumped. Eventualy there will be 5 or 6 calls to use this function on the Form.

    VB Code:
    1. Private Function FillForm(ByVal [B]column[/B] As String, ByVal [B]table[/B] As String, ByVal [B]cbobox[/B] As String)
    2.         Dim myconn As SqlConnection
    3.         Dim mycmd As SqlCommand
    4.         Dim myread As SqlDataReader
    5.         Dim output As String
    6.         Dim outputInt As String
    7.  
    8.         myconn = New SqlConnection (Bla,Bla,Bla)
    9.         myconn.Open()
    10.  
    11.         mycmd = myconn.CreateCommand()
    12.         mycmd.CommandText = ("select " & [B]column[/B] & " from " & [B]table[/B])
    13.         myread = mycmd.ExecuteReader()
    14.         While myread.Read()
    15.             output = output & myread.GetString(0)
    16.             [U][B]cbobox[/B].[/U]Items.Add(output)
    17.             output = ""
    18.         End While
    19.         myread.Close()
    20.         myconn.Close()
    21.         cboLocation.SelectedIndex = 1
    22.        
    23.     End Function

  2. #2

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: Passing Strings to function (SELF SOLVED DOH!)

    Bold shows Changes.
    Removing Quotes from cbolocation REALLY HELPS, Self DOHHH!!!
    VB Code:
    1. FillForm("PLocation", "Location", [B]cboLocation[/B])

    VB Code:
    1. Private Function FillForm(ByVal column As String, ByVal table As String, ByVal cbobox As [B]Object[/B])
    2.         Dim myconn As SqlConnection
    3.         Dim mycmd As SqlCommand
    4.         Dim myread As SqlDataReader
    5.         Dim output As String
    6.         Dim outputInt As String
    7.  
    8.         myconn = New SqlConnection (Bla,Bla,Bla)
    9.         myconn.Open()
    10.  
    11.         mycmd = myconn.CreateCommand()
    12.         mycmd.CommandText = ("select " & column & " from " & table)
    13.         myread = mycmd.ExecuteReader()
    14.         While myread.Read()
    15.             output = output & myread.GetString(0)
    16.             cbobox.Items.Add(output)
    17.             output = ""
    18.         End While
    19.         myread.Close()
    20.         myconn.Close()
    21.         cboLocation.SelectedIndex = 1
    22.        
    23.     End Function

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Passing Strings to function (SELF SOLVED DOH!)

    Actualy it would be better if you dclared it as an actual combobox, not as an object.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: Passing Strings to function (SELF SOLVED DOH!)

    Even Better THANX!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width