Results 1 to 27 of 27

Thread: [RESOLVED] exchange text values in an text box array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Resolved [RESOLVED] exchange text values in an text box array

    I wanted to exchange the text values of two text boxes in an array of 10 textboxes. I have tried writing the two texts to textboxes and then reading the opposite textbox, but that didn't work. Does anybody know how to do this? Thanks.
    Last edited by A-D-D-F_Toxic; Feb 26th, 2006 at 04:46 PM. Reason: More specific title

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exchange text values in an array

    We need more information. What have you tried? Post some code, and tell us what isn't working, and/or any errors that you are getting, including what line the error is on.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an array

    Yeah, good point. I have tried what I said I have tried, but I have also tried something like that, but putting the text in an array and taking the opposite. The method in my first post worked for list indexes of combo boxes. Now, what it does. I try exchanging the text of index 0 and 1, but what happens is very strange. I must have deleted my code when I realized that it wasn't working or something, because nothing happens now. But what I think happened earlier (I don't quite remember, it's been a while) is that index 4 got the text of index 5 and index 5's text was blank. These textboxes are on a different form than the exchange code is, too. No errors occur though.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exchange text values in an array

    Take a look at this. Add txt(0), txt(1), and a command button.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim str As String
    4.  
    5. Private Sub Command1_Click()
    6.   str = txt(0).Text
    7.   txt(0) = txt(1).Text
    8.   txt(1) = str
    9. End Sub
    10.  
    11. Private Sub Form_Load()
    12.   txt(0).Text = "here"
    13.   txt(1).Text = "there"
    14.   End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an array

    Wow! That's a good method by just sending the one text straight over. I'd love to try this and see if it finally works, but I'm out of time now, so I'll finish when I get a chance and tell you if you helped me.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an array

    Still, nothing happening. This is very strange. Since I have 10 textboxes and the user choses which to exchange the text value of, I have to have a bunch of if's to check which indexes to swith for each of those 3 lines. Maybe I am doing something wrong here.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    More details:
    I have two combo boxes listing the text boxes from the array. The first combo box is, in dglienna's example, selecting the txt(0) to use. The second combo is txt(1). The array is on a different form than the combo boxes that let you select the text boxes. Since it is on a different form, it could possibly be unloaded. I have created a backup procedure where all my text collects in strings when the form unloads and is taken from the strings when the form loads. The strings (in an array) are cleared after. It works. Because it recovers when the form loads, I made the form load and hide while exchanging the text. Here's my code:
    In General Declarations:
    VB Code:
    1. Option Explicit
    2. Dim intExchangeLI As Integer
    3. Dim intWithLI
    4. Dim DetailsExchange As String
    In my DetailsExchange Procedure (A Public Sub):
    VB Code:
    1. frmDetails.Show
    2.    
    3.     intExchangeLI = cboExchange.ListIndex
    4.     intWithLI = cboWith.ListIndex
    5.    
    6.     DetailsExchange = frmDetails.txtDetails(intExchangeLI)
    7.     frmDetails.txtDetails(intExchangeLI).Text = frmDetails.txtDetails(intWithLI).Text
    8.     frmDetails.txtDetails(intWithLI).Text = DetailsExchange
    9.    
    10.     frmDetails.Hide
    I used "Exchange" for any name about the first text box in the exchange. I used "With" for any name about the second text box in the exchange.
    Last edited by A-D-D-F_Toxic; Feb 26th, 2006 at 05:10 PM. Reason: Didn't mean to post

  8. #8
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    The options to choose from the comboboxes are the number of the textboxes to exchange or the content of those boxes?
    if the options are the numbers then use this:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim str As String
    4.  
    5. Private Sub Command1_Click()
    6.   str = txt(combo1.text - 1).Text
    7.   txt(combo1.text - 1) = txt(combo2.text - 1).Text
    8.   txt(combo2.text - 1) = str
    9. End Sub
    Last edited by Kanbei; Feb 26th, 2006 at 05:40 PM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    The text box selected is the list index from the combo boxes selected, so actually it's none of the above, answering your question. Now, to try this, it would be the same thing, but just "ListIndex" not "Text". Let me try that.
    -------------------------------------I try----------------------------------------
    It's still not working. I even tried it with "Text" like you put, not "List Index."

  10. #10
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: exchange text values in an text box array

    Ok so you got 10 textboxs all a array on form1 and 2 combo box's on form2.

    Cant you just do something like this on a command button on the first form
    VB Code:
    1. Private Sub Command1_Click()
    2. Form2.Show
    3. Me.Hide
    4. End Sub

    Loading up form2 and just hiding form1.

    Then for form2 put this in it

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strTxt As String
    3.  
    4. strTxt = Form1.Text1(Combo1.ListIndex)
    5. Form1.Text1(Combo1.ListIndex) = Form1.Text1(Combo2.ListIndex)
    6. Form1.Text1(Combo2.ListIndex) = strTxt
    7. Form1.Show
    8. Unload Me
    9. End Sub
    10.  
    11. Private Sub Form_Load()
    12. For i = 0 To 9
    13. Combo1.AddItem i
    14. Combo2.AddItem i
    15. Next i
    16. End Sub

    This should work, but are you sure none of the other codes work because they all looked fine to me. Also if these all dont work could you post some more code or post the project that you trying to do?
    Are we alive or just breathing?

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    Yes, that's what I have: 10 texts on Form1, and 2 combos on Form2. The first code that I got from David did work in it's own application, but not in mine. I have the button to open Form2 (combo boxes) on another form (I only hide this third form). When the exchange is done, it goes back to the third form. There are also list indexes that I exchange on that form (It works). The second form might hide, if the user selects close when they close it, it hides. The user might select the "x" instead, though, which unloads the form. Your way works in a seperate program, too, but not in mine. I am not ready to post my project, but maybe my little extra explanations here about what you seem to not understand will help.
    But here's some more code. Here's in my Public Sub Exchange() Sub. This is to exchange the list indexes on the third form that I was talking about:
    VB Code:
    1. 'If Details are being moved, then call
    2.     If chkMoveDetails.Value = True Then
    3.         Call MoveDetails
    4.     ElseIf chkMoveDetails.Value = False Then
    5.         'Take no effect
    6.     End If
    I only want the textboxes (details) exchanging if the user has checked a checkbox checked (It's called chkMoveDetails).
    VB Code:
    1. Public Sub MoveDetails()
    2.     Dim DetailsExchangeSpace As String
    3.     frmDetails.Show
    4.     frmDetails.txtDetails(0).Visible = True
    5.     frmDetails.txtDetails(1).Visible = True
    6.     frmDetails.txtDetails(2).Visible = True
    7.     frmDetails.txtDetails(3).Visible = True
    8.     frmDetails.txtDetails(4).Visible = True
    9.     frmDetails.txtDetails(5).Visible = True
    10.     frmDetails.txtDetails(6).Visible = True
    11.     frmDetails.txtDetails(7).Visible = True
    12.     frmDetails.txtDetails(8).Visible = True
    13.     frmDetails.txtDetails(9).Visible = True
    14.     frmDetails.Hide
    15.     DetailsExchange = frmDetails.txtDetails(cboExchange.ListIndex)
    16.     frmDetails.txtDetails(cboExchange.ListIndex) = txtDetails(cboExchange.ListIndex)
    17.     frmDetails.txtDetails(cboWith.ListIndex) = DetailsExchange
    18. End Sub
    frmDetails is the form with my textbox array on it. txtDetails is the textbox array.

  12. #12
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    i still don't get a few thing: why do you say the code is ok but not in YOUR program? something related with if the forms are loaded?

    anyways i think in that text you meant to say that you don't want the form to unload when the user presses X.

    If so then do this:
    VB Code:
    1. Private Sub FORMNAME_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. Cancel = True
    3. Me.Hide
    4. End Sub
    Query Unload fires before the form unloads, ALWAYS. If at the end of the sub Cancel = True then it doesnt unload.
    So here the form will hide.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    Well, that probably would work, but that's not what I was asking. I actually didn't know you could make it not unload on X_Click. What I meant by "It works in seperate program but not mine" is I have created a new project and put the code in that have been supplied to me. I tried it and it works, so I try it in the program that I'm making that I want to use the code in and it works. Still not working...very strange. Another thing that I did wrong, that I noticed before I tried this is I have two different string names. I dimed the string as "DetailsExchangeSpace" but wrote and read it as "DetailsExchange" and this is fixed now.
    It now looks something more like this:
    VB Code:
    1. '...Part of code here is unimportant and not shown here.
    2.     'If Details are being moved, then call
    3.     If chkMoveDetails.Value = True Then
    4.         Call MoveDetails
    5.     ElseIf chkMoveDetails.Value = False Then
    6.         'Take no effect
    7.     End If
    8. '...Part of code here is unimportant and not shown here.
    9. Public Sub MoveDetails()
    10.     Dim DetailsExchangeSpace As String
    11.     DetailsExchangeSpace = frmDetails.txtDetails(cboExchange.ListIndex)
    12.     frmDetails.txtDetails(cboExchange.ListIndex) = txtDetails(cboExchange.ListIndex)
    13.     frmDetails.txtDetails(cboWith.ListIndex) = DetailsExchangeSpace
    14.     DetailsExchangeSpace = ""
    15. End Sub
    Another thing that I did was cleared the string after.

  14. #14
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    i think this line:
    frmDetails.txtDetails(cboExchange.ListIndex) = txtDetails(cboExchange.ListIndex)
    should be like this:
    frmDetails.txtDetails(cboExchange.ListIndex) = txtDetails(cboWith.ListIndex)

    maybe that's it, but if have mroe problems tell me plz what results you get: an error? nothing happens?

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    LOL, whoops! You're right, I wrote the wrong name again. I fixed that and it's still not working (Nothing happens). I looked at the code that you just typed for me to tell me where my mistake was, and noticed that I didn't specify a form on the second txtDetails. So I fixed that little problem, and still nothing happens. Like usual.

  16. #16
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    weird... it isnt a very complicated code... dunnow whats wrong
    u sure all names are correct?

    post all the button's code.

    meanwhile my advice for you to find out yourself:
    save that code it a word file and start over but do it in parts.
    first just make one text go to another.
    then assign the text content to a var and put it in a msgbox.
    and so on... maybe this way you'll find out WHAT PART of the code is wrong or missing something

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    Interesting advice.
    Code (I'm not posting all code in the program, that's lots):
    Important frmDetails Code:
    VB Code:
    1. Private Sub mnuFileClose_Click()
    2.     Me.Hide
    3. End Sub
    4. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    5.     Cancel = True
    6.     Me.Hide
    7.     frmMain.Show
    8. End Sub
    All frmMove code:
    VB Code:
    1. Option Explicit
    2. Private Sub cmdCancel_Click()
    3.     cboExchange.ListIndex = -1
    4.     cboWith.ListIndex = -1
    5.     Me.Hide
    6. End Sub
    7.  
    8. Private Sub cmdOk_Click()
    9.     If cboExchange.ListIndex = cboWith.ListIndex Then
    10.         MsgBox "Please select two seperate list items", , "Sorry!"
    11.     ElseIf cboExchange.ListIndex = -1 Then
    12.         MsgBox "Please select a list item to exchange.", , "Sorry!"
    13.     ElseIf cboWith.ListIndex = -1 Then
    14.         MsgBox "Please select a list item to exchange.", , "Sorry!"
    15.     Else
    16.         cboExchange.Enabled = False
    17.         cboWith.Enabled = False
    18.         Call Exchange
    19.     End If
    20. End Sub
    21. Public Sub Exchange()
    22.     'Insert listindex's into Exchange1
    23.     If cboExchange.ListIndex = 0 Then
    24.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption1.ListIndex
    25.     ElseIf cboExchange.ListIndex = 1 Then
    26.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption2.ListIndex
    27.     ElseIf cboExchange.ListIndex = 2 Then
    28.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption3.ListIndex
    29.     ElseIf cboExchange.ListIndex = 3 Then
    30.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption4.ListIndex
    31.     ElseIf cboExchange.ListIndex = 4 Then
    32.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption5.ListIndex
    33.     ElseIf cboExchange.ListIndex = 5 Then
    34.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption6.ListIndex
    35.     ElseIf cboExchange.ListIndex = 6 Then
    36.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption7.ListIndex
    37.     ElseIf cboExchange.ListIndex = 7 Then
    38.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption8.ListIndex
    39.     ElseIf cboExchange.ListIndex = 8 Then
    40.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption9.ListIndex
    41.     ElseIf cboExchange.ListIndex = 9 Then
    42.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption10.ListIndex
    43.     End If
    44.     'Insert listindex's into Exchange2
    45.     If cboWith.ListIndex = 0 Then
    46.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption1.ListIndex
    47.     ElseIf cboWith.ListIndex = 1 Then
    48.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption2.ListIndex
    49.     ElseIf cboWith.ListIndex = 2 Then
    50.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption3.ListIndex
    51.     ElseIf cboWith.ListIndex = 3 Then
    52.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption4.ListIndex
    53.     ElseIf cboWith.ListIndex = 4 Then
    54.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption5.ListIndex
    55.     ElseIf cboWith.ListIndex = 5 Then
    56.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption6.ListIndex
    57.     ElseIf cboWith.ListIndex = 6 Then
    58.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption7.ListIndex
    59.     ElseIf cboWith.ListIndex = 7 Then
    60.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption8.ListIndex
    61.     ElseIf cboWith.ListIndex = 8 Then
    62.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption9.ListIndex
    63.     ElseIf cboWith.ListIndex = 9 Then
    64.         frmExchangeSpace.txtExchange2.Text = frmMain.cboOption10.ListIndex
    65.     End If
    66.     'Read Exchange2
    67.     If cboExchange.ListIndex = 0 Then
    68.         frmMain.cboOption1.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    69.     ElseIf cboExchange.ListIndex = 1 Then
    70.         frmMain.cboOption2.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    71.     ElseIf cboExchange.ListIndex = 2 Then
    72.         frmMain.cboOption3.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    73.     ElseIf cboExchange.ListIndex = 3 Then
    74.         frmMain.cboOption4.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    75.     ElseIf cboExchange.ListIndex = 4 Then
    76.         frmMain.cboOption5.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    77.     ElseIf cboExchange.ListIndex = 5 Then
    78.         frmMain.cboOption6.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    79.     ElseIf cboExchange.ListIndex = 6 Then
    80.         frmMain.cboOption7.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    81.     ElseIf cboExchange.ListIndex = 7 Then
    82.         frmMain.cboOption8.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    83.     ElseIf cboExchange.ListIndex = 8 Then
    84.         frmMain.cboOption9.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    85.     ElseIf cboExchange.ListIndex = 9 Then
    86.         frmMain.cboOption10.ListIndex = Val(frmExchangeSpace.txtExchange2.Text)
    87.     End If
    88.     'Read Exchange1
    89.     If cboWith.ListIndex = 0 Then
    90.         frmMain.cboOption1.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    91.     ElseIf cboWith.ListIndex = 1 Then
    92.         frmMain.cboOption2.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    93.     ElseIf cboWith.ListIndex = 2 Then
    94.         frmMain.cboOption3.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    95.     ElseIf cboWith.ListIndex = 3 Then
    96.         frmMain.cboOption4.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    97.     ElseIf cboWith.ListIndex = 4 Then
    98.         frmMain.cboOption5.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    99.     ElseIf cboWith.ListIndex = 5 Then
    100.         frmMain.cboOption6.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    101.     ElseIf cboWith.ListIndex = 6 Then
    102.         frmMain.cboOption7.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    103.     ElseIf cboWith.ListIndex = 7 Then
    104.         frmMain.cboOption8.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    105.     ElseIf cboWith.ListIndex = 8 Then
    106.         frmMain.cboOption9.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    107.     ElseIf cboWith.ListIndex = 9 Then
    108.         frmMain.cboOption10.ListIndex = Val(frmExchangeSpace.txtExchange1.Text)
    109.     End If
    110.     'If Details are being moved, then call
    111.     If chkMoveDetails.Value = True Then
    112.         Call MoveDetails
    113.     ElseIf chkMoveDetails.Value = False Then
    114.         'Take no effect
    115.     End If
    116.     'Resume view to normal
    117.     frmExchangeSpace.txtExchange1.Text = "" 'Delete exchange space list index's
    118.     frmExchangeSpace.txtExchange2.Text = "" 'Delete exchange space list index's
    119.     cboExchange.Enabled = True 'This was disabled during the move
    120.     cboWith.Enabled = True  'This was disabled during the move
    121.     cboExchange.ListIndex = -1 'No item is being moved
    122.     cboWith.ListIndex = -1 'No item is being moved
    123.     Me.Hide
    124. End Sub
    125. Public Sub MoveDetails()
    126.     Dim DetailsExchangeSpace As String
    127.     DetailsExchangeSpace = frmDetails.txtDetails(cboExchange.ListIndex)
    128.     frmDetails.txtDetails(cboExchange.ListIndex) = frmdetail.txtDetails(cboWith.ListIndex)
    129.     frmDetails.txtDetails(cboWith.ListIndex) = DetailsExchangeSpace
    130.     DetailsExchangeSpace = ""
    131. End Sub
    One thing I know I could've done better is exchangin the list indexes on frmMain, putting it in arrays rather than little text boxes on an unshown form. Also, I set the enabled property to false while moving, just incase somebody decides to get a slow computer and then change the values in the middle of the move and then the move reads something different.

  18. #18
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    that is lot of code...
    continuing my prevoius advice: in order to find your problem make your code more clear:
    those cboOptionX could be an array of controls, know how to make them?
    if you do then for example this long code:
    VB Code:
    1. 'Insert listindex's into Exchange1
    2.     If cboExchange.ListIndex = 0 Then
    3.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption1.ListIndex
    4.     ElseIf cboExchange.ListIndex = 1 Then
    5.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption2.ListIndex
    6.     ElseIf cboExchange.ListIndex = 2 Then
    7.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption3.ListIndex
    8.     ElseIf cboExchange.ListIndex = 3 Then
    9.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption4.ListIndex
    10.     ElseIf cboExchange.ListIndex = 4 Then
    11.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption5.ListIndex
    12.     ElseIf cboExchange.ListIndex = 5 Then
    13.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption6.ListIndex
    14.     ElseIf cboExchange.ListIndex = 6 Then
    15.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption7.ListIndex
    16.     ElseIf cboExchange.ListIndex = 7 Then
    17.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption8.ListIndex
    18.     ElseIf cboExchange.ListIndex = 8 Then
    19.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption9.ListIndex
    20.     ElseIf cboExchange.ListIndex = 9 Then
    21.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption10.ListIndex
    22.     End If

    could be cut in just this:
    VB Code:
    1. frmExchangeSpace.txtExchange1.Text = frmMain.cboOption(cboExchange.ListIndex).ListIndex

    i know this wont solve your problem, but one thing i've learnt very well is that in 10 pages of code is harder to find a mistake.

    if you turn all that code into 5 lines.... life is easier
    if you dont knwo how to do it tell me and ill write the whole code (it should be a line per "section" of IFs)

  19. #19
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: exchange text values in an text box array

    Quote Originally Posted by Kanbei
    that is lot of code...
    continuing my prevoius advice: in order to find your problem make your code more clear:
    those cboOptionX could be an array of controls, know how to make them?
    if you do then for example this long code:
    VB Code:
    1. 'Insert listindex's into Exchange1
    2.     If cboExchange.ListIndex = 0 Then
    3.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption1.ListIndex
    4.     ElseIf cboExchange.ListIndex = 1 Then
    5.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption2.ListIndex
    6.     ElseIf cboExchange.ListIndex = 2 Then
    7.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption3.ListIndex
    8.     ElseIf cboExchange.ListIndex = 3 Then
    9.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption4.ListIndex
    10.     ElseIf cboExchange.ListIndex = 4 Then
    11.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption5.ListIndex
    12.     ElseIf cboExchange.ListIndex = 5 Then
    13.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption6.ListIndex
    14.     ElseIf cboExchange.ListIndex = 6 Then
    15.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption7.ListIndex
    16.     ElseIf cboExchange.ListIndex = 7 Then
    17.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption8.ListIndex
    18.     ElseIf cboExchange.ListIndex = 8 Then
    19.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption9.ListIndex
    20.     ElseIf cboExchange.ListIndex = 9 Then
    21.         frmExchangeSpace.txtExchange1.Text = frmMain.cboOption10.ListIndex
    22.     End If

    could be cut in just this:
    VB Code:
    1. frmExchangeSpace.txtExchange1.Text = frmMain.cboOption(cboExchange.ListIndex).ListIndex

    i know this wont solve your problem, but one thing i've learnt very well is that in 10 pages of code is harder to find a mistake.

    if you turn all that code into 5 lines.... life is easier
    if you dont knwo how to do it tell me and ill write the whole code (it should be a line per "section" of IFs)


    you can also use the select case statement to replace the if...elseif......endif statement.
    that would in a way give a clearer view of the flow

    VB Code:
    1. select case cboExchange.ListIndex
    2.         case 1: '<a line of code here>
    3.         case 2: '<another line>
    4.         'and so on and so forth
    5. end select
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    I've used my cboOptions in code so much, that if I put them in an array, I will have to change lots of code that has it already. Like I said already, that part works. The problem is that the DetailsExchange procedure doesn't work.
    d3gerald, I am familiar with nothing of your little code except cboExchange.ListIndex.

  21. #21
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: exchange text values in an text box array

    Sorry then i wouldn't know what to tell you, so again my advices:
    - Run the program step by step (with F8 you go to the next step) and you can see each var's value in every step.

    - Add to your code some msgboxes showing var's and control's values in a precise moment so you see if they have the value you expected

    - And again: YOU REALLY SHOULD make those combos an array of control. Suppose you find a mistake now: you would have to correct it in 700 lines.
    If you create an array you will have the chance to start from the scratches and probably find the mistake, and if not, when you find the mistake you will correct only a couple of lines.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: exchange text values in an text box array

    I forgot about that next step thing.
    And if I change them to arrays now, then I have to change 700 lines to array format! I might get it into an array once this is figured out.l
    Well, I just opened the project, and apparently I commented something out that the program didn't like, because my frmDetails doesn't work, now.
    VB's making me a bit mad right now, and I just ran out of time. I'll see if I can get patient with it sometime later.

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Exclamation Re: exchange text values in an text box array

    I'm back on the problem again. The problem actually isn't in the code of moving my texts. I commented everything out in the if (it's an if now, not a new sub) of the text moving and put a message box in there. I tried moving the texts and I didn't get the message, so that means that there's something wrong with getting to the procedure.
    VB Code:
    1. If chkDetails.Value = True Then
    2.         Dim detailsExchangeSpace As String
    3.         detailsExchangeSpace = frmDetails.txtDetails(frmExchange.cboExchange(0).ListIndex)
    4.         frmDetails.txtDetails(cboExchange(0).ListIndex) = frmDetails.txtDetails(cboExchange(1).ListIndex)
    5.         frmDetails.txtDetails(cboExchange(1).ListIndex) = detailsExchangeSpace
    6.     End If
    I took the message box out of this sample of code. Another thing I changed was "cboExchange" and "cboWith" which are now in an array called "cboExchange."

  24. #24
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: exchange text values in an text box array

    Try:

    VB Code:
    1. If chkDetails.Value = vbChecked Then

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Resolved Re: exchange text values in an text box array

    I knew I wasn't understanding the checkboxes "checked" property in code. That worked much better, thanks! Woohoo!

  26. #26
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [RESOLVED] exchange text values in an text box array

    BTW, you can shorten all that If...ElseIf code you were using without using a control array:
    VB Code:
    1. frmExchangeSpace.txtExchange1.Text = frmMain.Controls("cboOption" & cboExchange.ListIndex).ListIndex
    That way you don't need to rename all your controls

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Re: [RESOLVED] exchange text values in an text box array

    I didn't rename it, I'm remaking the whole program...I know it might sound strange, it seemed to screw up more and more with everything I did, so I just redid it...there were lots of things to change, anyway, like that array, which would actually make it easier in lots of places, but thanks for the code.

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