Results 1 to 6 of 6

Thread: Loop and Modifying Variables

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    This is the code I am using now:

    Code:
    Public Sub generatewebpageonead()
    Dim codenumbertitleloop As Integer
    Dim codenumberbodyloop As Integer
    totalrecords = Form3.codetotal
    codenumbertitleloop = 1
    codenumberbodyloop = 1
    Do
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumbertitleloop & ".cdt") For Input As #1
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumberbodyloop & ".cdb") For Input As #2
    Input #1, temptitle
    Input #2, tempbody
    Close #1
    Close #2
    -----
    'NEED TO MODIFY VARIABLE CODE HERE
    'eg: codetitle & codenumbertitleloop = temptitle           is invalid
    
    MsgBox codenumbertitleloop
    MsgBox cdbody
    If codenumbertitleloop = totalrecords Then End
    codenumbertitleloop = Val(codenumbertitleloop) + 1
    codenumberbodyloop = Val(codenumbertitleloop) + 1
    Loop
    I want the variable to increse by one every time the program loops, but it keeps giving me an error message.

    Any way to do this. For example, say i want a varaible

    codetitle01 = codetemp

    and next time it loops i want the variable to be

    codetitle02 = codetemp



    Any way to do this?

    [Edited by Wrestlecar Webmaster on 08-03-2000 at 04:54 PM]

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You don't need to use Val() function as codenumbertitleloop already is a numeric value (integer)

    Otherways i don't see anything wrong, except if your program will end at the If line. You could put a break there and check if it ever get's there

    And what and where's the error you get?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    Will the following code work in VB4?

    Code:
    Public Sub generatewebpageonead()
    Dim codenumbertitleloop As Integer
    Dim codenumberbodyloop As Integer
    totalrecords = Form3.codetotal
    codenumbertitleloop = 1
    codenumberbodyloop = 1
    Do
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumbertitleloop & ".cdt") For Input As #1
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumberbodyloop & ".cdb") For Input As #2
    Input #1, temptitle
    Input #2, tempbody
    Close #1
    Close #2
    
    codetitle & codenumbertitleloop = temptitle 'ERRORS ON THIS LINE
    codebody & codenumberbodyloop = tempbody 'ERRORS ON THIS LINE
    
    
    MsgBox codenumbertitleloop
    MsgBox cdbody
    If codenumbertitleloop = totalrecords Then End
    codenumbertitleloop = Val(codenumbertitleloop) + 1
    codenumberbodyloop = Val(codenumbertitleloop) + 1
    Loop

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

    <?>

    'hope this in some way helps..
    'it increments now

    Code:
    ' take the open and close out of the loop
    'that's a lot of overhead for no reason
    
    
    Public Sub generatewebpageonead()
    
    Dim codenumbertitleloop As Integer
    Dim codenumberbodyloop As Integer
    
    totalrecords = Form3.codetotal
    codenumbertitleloop = 1
    codenumberbodyloop = 1
    
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumbertitleloop & ".cdt") For Input As #1
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumberbodyloop & ".cdb") For Input As #2
    
    
    Do
    
    Input #1, temptitle
    Input #2, tempbody
    
    
    'NEED TO MODIFY VARIABLE CODE HERE
    'eg: codetitle & codenumbertitleloop = temptitle           is invalid
    
    If codenumbertitleloop = totalrecords Then
       MsgBox codenumbertitleloop
    Exit Sub
    
    Else
      codenumbertitleloop = codenumbertitleloop + 1
       codenumberbodyloop = codenumbertitleloop + 1
    End If
    
    Loop
    
    Close #1
    Close #2
    
    
    'I have no idea what you are trying to do here.
    
    '<<<<<<<<<<<<  ???????????????????  >>>>>>>>>>>>>
    
    'I want the variable to increse by one every time the
    'program loops, but it keeps giving me an error message.
    
    'Any way to do this. For example, say i want a varaible
    
    'what is codetemp
       'codetitle01 = codetemp
    
    'and next time it loops i want the variable to be
    
      'codetitle02 = codetemp
    
    
    End Sub
    
    
    Private Sub Form_Load()
       Call generatewebpageonead
    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    Code:
    Public Sub generatewebpageonead()
    Dim codenumbertitleloop As Integer
    Dim codenumberbodyloop As Integer
    totalrecords = Form3.codetotal
    codenumbertitleloop = 1
    codenumberbodyloop = 1
    Do
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumbertitleloop & ".cdt") For Input As #1
    Open (App.Path & "/codes/" & (Form2.address) & "/code" & codenumberbodyloop & ".cdb") For Input As #2
    Input #1, temptitle
    Input #2, tempbody
    Close #1
    Close #2
    
    codetitle & codenumbertitleloop = temptitle 'ERRORS ON THIS LINE
    codebody & codenumberbodyloop = tempbody 'ERRORS ON THIS LINE
    
    
    MsgBox codenumbertitleloop
    MsgBox cdbody
    If codenumbertitleloop = totalrecords Then End
    codenumbertitleloop = Val(codenumbertitleloop) + 1
    codenumberbodyloop = Val(codenumbertitleloop) + 1
    Loop

    What I am trying to do is extract a title and body paragraph from various text documents. The documents are named ....01 ....02 ....03 .....04 etc...

    There is a different number of documents each time, and thats what "If codenumbertitleloop = totalrecords Then End" line means. If the total number of text documents is equal to the current document, then do not continue.

    I need it to save the data from the text documents into variables.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    codetitle & codenumbertitleloop = temptitle 'ERRORS ON THIS LINE
    codebody & codenumberbodyloop = tempbody 'ERRORS ON THIS LINE
    Hmm..
    This shows what you're trying to do, but it doesn't work this way.
    You should search for a delimiter with Instr$ function in the strings, then separate the strings with Left$ and Mid$
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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