Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 16th, 2004, 04:36 PM
Authorized User
 
Join Date: Jun 2003
Location: Mexico City, Distrito Federal, Mexico.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with arrays created from textbox entries

Hi all,

Moving on to ever increasing complexity and now I am stuck again.

Let me explain the problem. I have a form representing members of a group, which includes a MSHFlexGrid containing a list of all users in the database and below that I have a large textbox. When I double click on a user in the flexgrid it appears in the texbox below (Showing that user is add to the group. If there is more than one user choosen they are seperated by a (;) semicolon. When the user has finished selecting all the users they want in the current group they click "OK". When the OK button is clicked I SPLIT the contents of the textbox using the (;) as the delimiter. Obviously after I have an array with the contents of the textbox. What I want to do is add a new user to the group in the database. I need to FOR NEXT loop through them putting each one in the database. Sounds simple but before I do that I have to extract the UserID Number from the user table because this is the reference that is placed in the group database. e.g. GroupID and IDNumber

Here is my code so far:

---------------------------------------------------------------------------------------------------

Public strAdd As String

Private Sub Form_Load()

  ' Assign value
  rsClickCount = 0

  ' Create fixed row headers and widths
  MSHFlexGrid1.FormatString = "|User ||Description |"

  ' Set unwanted columns to o width
  MSHFlexGrid1.ColWidth(0) = 0
  MSHFlexGrid1.ColWidth(2) = 0
  MSHFlexGrid1.ColWidth(4) = 0
  MSHFlexGrid1.ColWidth(5) = 0

  ' Enable AllowBigSelection
  MSHFlexGrid1.AllowBigSelection = True

  ' Create an SQL Statement.
  Dim strSQL As String
  strSQL = "SELECT * FROM Users ORDER BY Name"

  ' Assign the ConnectionString to an ADO Data Control's
  ' ConnectionString property, and the SQL Statement to the
  ' control's RecordSource property.
  With Adodc1
    .ConnectionString = strCn
    .RecordSource = strSQL
  End With

  ' Set the HflexGrid control's DataSource property to the
  ' ADO Data control.
  Set MSHFlexGrid1.DataSource = Adodc1

  ' Refresh MSHFlexGrid
  Adodc1.Refresh
  MSHFlexGrid1.Refresh

End Sub
Private Sub cmdCancel_Click()

  'Unload form
  Unload frm_UserSelect

End Sub

Private Sub MSHFlexGrid1_DblClick()

  ' Declare variables
  Dim r As Integer
  Dim rsName As String
  Dim rsSelectOutput As String

  ' Assign variable and identify row selected
  r = MSHFlexGrid1.MouseRow

  If rsClickCount = 0 Or Text1.Text = "" Then
    Text1.Text = ""
    rsName = MSHFlexGrid1.TextMatrix(r, 1)
    rsSelectOutput = rsName
    rsClickCount = rsClickCount + 1
  Else
    rsName = MSHFlexGrid1.TextMatrix(r, 1)
    rsSelectOutput = "; " & rsName
    rsClickCount = rsClickCount + 1
  End If
  Text1.Text = Text1.Text & rsSelectOutput

End Sub

Function CreateArray(UserArray As Variant) As Variant
    UserArray = Split(strAdd, ";")
End Function

Private Sub cmdOK_Click()

  ' Check to see if user has been selected
  If Text1.Text = "<< Type names separated by semicolons or choose from list >>" Then
    ' Unload current window
    Unload frm_UserSelect
  End If
  If Text1.Text = "" Then
    ' Unload current window
    Unload frm_UserSelect
  Else
    Dim oRS As ADODB.Recordset
    strAdd = Trim$(Text1.Text)
    strAdd = Replace(strAdd, " ", "")
    txbTest.Text = strAdd
    CreateArray (UserArray)

    Dim r As Long
    For r = 0 To UBound(UserArray) <------------------------------------------ Problem starts here
      ' Create an SQL Statement that will extract IDNumber from
      ' database in relation to User name selected
      Dim strSQL As String
      strSQL = "SELECT IDNumber, Name FROM Users WHERE Name = '" & UserArray(r) & "'"

      ' Create Recordset and Populate Combo1.
      Dim rst As New ADODB.Recordset
      rst.Open strSQL, strCn
      rsIDNumber = rst!IDNumber
      rst.Close
      Set rst = Nothing

      ' Open database link
      oRS.Open "GroupMembers", strCn, adOpenKeyset, adLockOptimistic
      oRS.AddNew
      oRS.Fields("IDNumber") = rsIDNumber
      oRS.Fields("GroupID") = rsGroupSelected
      oRS.Update
      oRS.Close
    Next

  End If

  ' Close form
  Unload frm_UserSelect

  ' Empty array
  UserArray = Empty

End Sub

---------------------------------------------------------------------------------------------------

The problem comes when I try to open the array from a different sub routine. I am completely unsure of how you handle arrays as I am very new to this programming technique. Look through my code to see if I have structured the program properly in order to achieve a filled data base.

If anyone has any documentation on arrays this would be greatly received as I am trying deperately to understand its inner workings.

With many thanks for you time and assistance

Paul
Reply With Quote
  #2 (permalink)  
Old October 20th, 2004, 01:09 PM
Aal Aal is offline
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi ... sorry about my english
you didn't specify the problems throught the array ( the message is ) ??
check your StrAdd Vars that you access twice, why don't u manage that vars in the
same function that u created ( Replace ... ). check the ubound of UserArray that
belongs to Create_Array parameters. If u mean that your function returning result in array, check again the way u make it. Then try to loops from 1 to ubound(vArr)-1
Sorry i can't give u more than this, cause i'm in the net right now.
hope this usefull for u in concepting your scripts...bye

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
WAT created Membership not working zoltac007 ASP.NET 2.0 Basics 0 December 21st, 2006 03:52 PM
TextBox issues when created programatically nkommala ASP.NET 1.x and 2.0 Application Design 3 October 10th, 2006 12:59 AM
Working with Arrays arnabghosh Classic ASP Basics 5 October 21st, 2005 12:50 AM
Working with arrays created from textbox entries neo_jakey Beginning VB 6 4 September 17th, 2004 03:02 PM



All times are GMT -4. The time now is 10:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.