Results 1 to 8 of 8

Thread: a loop.....i think!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    WALES UK
    Posts
    31

    Talking

    fairly simple really... i have a program that gives me six random numbers every time I click the button and it sores them in the database..

    all I want to do is promt the user to enter the number of enries they wish to input into the database through an input box...so if they selected 10 it would loop through my code 10 times and add these to my database..any ideas??
    cheers...

    Rhys

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Code:
    Dim Temp as String
    Dim A as Long
    
    Temp = InputBox( "Enter number:" )
    
    If IsNumeric( Temp ) Then
      For A = 1 to Temp
        AddItem InputBox( "Enter Item number " & A & ":" )
      Next
    Endif
    Is that what you are looking for?

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    /?\

    Private Sub Command1_Click()
    Dim sNumbers As Integer
    Dim newNum As Integer
    Dim i As Integer

    sNumbers = InputBox("Enter your numbers")
    Randomize
    Dim iArr()
    For i = 1 To sNumbers
    ReDim iArr(sNumbers)
    newNum = Int(Rnd * sNumbers)
    iArr(i) = newNum


    List1.AddItem 'this is just for display
    'remove it and save your stuff to your database here

    ' ie. data1.recordset!storenumberfield = iarr(i)

    Next i


    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    WALES UK
    Posts
    31

    Unhappy

    All I want it do is repaet the code behind the button..so if they press 10 times it does it 10 times instead of having to press the button 10 times....can you see what im saying..cos im starting to confuse myself!!!!!!!!!


    Rhys :0)

  5. #5
    Guest
    Try this. Make a Form with a FlexGrid and place the following code into a CommandButton.

    Code:
    Private Sub Command1_Click()
    
        Dim RetVal As Integer
        Dim MyNum As Integer
        'Get how many entries (How many times to loop the code)
        RetVal = InputBox("How many entries?")
        
        'Loop it was many times as specified in RetVal
        For X = 1 To RetVal
        
            For I = 1 To 6
                'Generate Random Numbers
                Randomize
                MyNum = Int(Rnd * 100) + 1
                'Adds to the next column in the FlexGrid
                MSFlexGrid1.AddItem Chr(9) & MyNum
            Next I
            
        Next X
        
    End Sub

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    WALES UK
    Posts
    31
    my code is below:
    as you will see it adds the numbers to each different label although the above suggestion is what I want how can I get it to do this on my code so that each label can be added to the database.

    ???????????????



    Dim x As Integer
    Dim y As Integer

    Dim Numbers(1 To 50) As Boolean
    Dim Labels(1 To 6) As Integer
    Dim TempInt As Integer




    Private Sub Command1_Click()
    End

    End Sub

    Private Sub Command2_Click()
    Data1.Recordset.AddNew
    For x = 1 To 50
    Numbers(x) = False
    Next x
    x = 0
    Do
    x = x + 1
    Randomize
    TempInt = Int((Rnd * 49) + 1)
    For y = 1 To 50
    If TempInt = y Then
    If Not Numbers(y) Then
    Numbers(y) = True
    Labels(x) = TempInt
    Exit For
    Else
    x = x - 1
    Exit For
    End If
    End If
    Next y
    Loop Until x = 6
    Text1.Text = Labels(1)
    Text2.Text = Labels(2)
    Text3.Text = Labels(3)
    Text4.Text = Labels(4)
    Text5.Text = Labels(5)
    Text6.Text = Labels(6)





    End Sub





  7. #7
    Guest
    Try placing this at the end of your code. It will loop through through Labels and add it to the FlexGrid.

    Code:
    For I = 1 To 6
    
        'Loop through the labels and add them
        MSFlexGrid1.AddItem Chr(9) & (Labels(I))
    
    Next I

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    /???\

    in your form active or whereever
    open your database and set your datacontrol/recordset


    'adjust your code betweent he lines next y and loop until


    Next y
    yourdatacontrol.yourrecordset.addnew
    yourdatacontrol.yourrecordset!yourfield = labels(x)
    yourdatacontrol.yourrecordset.update

    Loop Until x = 6

    close your database on exit from app
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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