Search code examples
vb6

Visual Basic 6.0 Inbox formatting input


In my new project I need to format the outcome from the Inputbox going to TextBox.The Input are the numbers from 1 to 9.My input into the Inputbox looks like: exp... 123 OK, 234 OK, 456 OK...and so and so, NO SPACE.There will be a lot of numbers to manually enter. Those numbers later will be stored and will be occasionally added and processed for the highest number, and number of multiple repeats. This part I have already lined up.The TexBox must look: each line of 3 numbers separated by spase with single vbnewline:

1 2 3

2 3 4

5 6 7

I try to achieve this with this simple code, but that idea does not work:

For i = 1 To a
   ans = InputBox(".........")

   If ans = "" Then
      Exit Sub
   Else
      For b = 1 To 3
         Inp = Inp & Mid$(ans, b, 1) & " "
      Next

      Text1.Text = Inp & vbCrLf    ' or vbnewLine

   End if

Next

From all of this I am getting: 1 2 3 2 3 4 5 6 7 8 9...etc... no vbnewline

Any help in the matter would be much appreciated.

I did not get what I was looking for.


Solution

  • I tweaked your code a little bit to achieve the desired results:

    For i = 1 To a
       ans = InputBox(".........")
     
       If ans = "" Then Exit Sub
          
       Inp = ""
       
       For b = 1 To 3
          Inp = Inp & Mid$(ans, b, 1) & " "
       Next
    
       Text1.Text = Text1.Text & Inp & vbCrLf & vbCrLf
    Next
    

    However, this can be done more simply using the Format command:

    For i = 1 To a
       ans = InputBox(".........")
       
       If ans = "" Then Exit Sub
          
       Text1.Text = Text1.Text & Format(ans, "@ @ @") & vbCrLf & vbCrLf
    Next