Results 1 to 7 of 7

Thread: Trouble With A Sub...

  1. #1
    Guest

    Post

    Ok, im trying to take a Sub if found in a QBasic program and put it in VBasic. What the sub does is instead of just putting text onto the screen, it puts up one letter at a time. Its like someone was typing it.

    Here is the code for it in QBasic..

    ---Start Code---

    SUB printit (pstring AS STRING, row1 AS INTEGER, row2 AS INTEGER, c1 AS INTEGER, c2 AS INTEGER)
    length = LEN(pstring$): xnuym = 0
    FOR i = 1 to length
    xum = xnum + 1
    CurrentTimer! = TIMER: WHILE TIMER < (CurrentTimer! + (4 / 100))
    WEND
    LOCATE row1, row2
    COLOR c1, c2: PRINT LEFT$(pstring$, xnum)
    NEXT i
    END SUB

    ---End Code---

    The problem is, i dont know of a control that uses the command PRINT. If you know of a control i should use, or if you have an idea of what i should do, or if you think it wont work for some reason, please let me know.

    Thanks...

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    The Form, and picturebox controlls use print. You don't want to do it like that though, VB is an event orientated language, use the timer controll.

  3. #3
    Guest
    Hello,

    You could use something like this:

    Code:
    Public Sub WriteText(txtBox As TextBox, sTextIn As String, sSec As Single)
      
      Dim I As Integer, snStartTime As Single, snCurTime As Single
      Dim bOk As Boolean
      
      For I = 1 To Len(sTextIn)
        bOk = False
        snStartTime = Format(Now, "SS")
        Do While bOk = False
        snCurTime = Format(Now, "SS")
        
        ' this can be done better
        ' I have a waitsub somewhere
        ' but I can't find it right now
        If snCurTime > snStartTime + sSec Then
          txtBox.Text = txtBox.Text & Mid(sTextIn, I, 1)
          bOk = True
        End If
        DoEvents
        Loop
      Next I
      
    End Sub
    Hope it helps,

    Best

  4. #4
    Guest

    Post Thanks

    RvA,
    Thanks for replying but i cant seem to get it to work. Could you go into some more detail on how to get it to work.

    Thanks...

  5. #5
    Guest
    Hello,

    Ok I did make this work on my machine, it will need some tunning as it was just a quick workup. I didn'r save the project so I will just explain what I did.


    I'll explain the sub first.

    Code:
    ' Declare the sub with the vars to pass to it
    Public Sub WriteText(txtBox As TextBox, sTextIn As String, sSec As Single)
      
      ' declare some local vars to use
      Dim I As Integer, snStartTime As Single, snCurTime As Single
      Dim bOk As Boolean
      
      ' create a loop so we can work down the input string
      For I = 1 To Len(sTextIn)
        ' set a var so we can break out of the loop later on
        bOk = False
        ' get the current seconds from the system so
        ' we have something to compaire against
        snStartTime = Format(Now, "SS")
        ' create a loop so we can stall the program for a short time
        Do While bOk = False
        ' now were in the stalling loop
        ' so let's see if the enough time
        ' has gone by
        snCurTime = Format(Now, "SS")
        
        ' this can be done better
        ' I have a waitsub somewhere
        ' but I can't find it right now
        If snCurTime > snStartTime + sSec Then
          ' the right amount of time has gone by
          ' so let's place a char from the string 
          ' into the textbox
          txtBox.Text = txtBox.Text & Mid(sTextIn, I, 1)
          ' we did what we wanted to do
          ' so break out of the loop 
          ' so we can get the next char
          bOk = True
        End If
        ' give the system some time
        DoEvents
        ' loop again
        Loop
        ' go get the next char
      Next I
      
      ' where all done get out :)
    End Sub

    The to use this sub you would need to call from a command button or something like this

    Code:
    Private Sub Command1_Click()
      ' declare a var to use
      Dim sText as String
    
      ' crate a string to print
      sText = "Print This Really Slow"
    
      ' call the function with the textbox name
      ' the string we want to pring
      ' and how long to wait between char's
      Call WriteText(Text1 , sText, 1)
      
      ' were done 
    End Sub
    If you copy the code section into a new project add one textbox and one command button and then run the app it should work. If not let me know what it's doing.

    Hope this helps a little,

    Best

    [Edited by RvA on 05-06-2000 at 08:35 PM]

    [Edited by RvA on 05-06-2000 at 08:36 PM]

  6. #6
    Guest

    Post Thanks

    Thanks, its working now, but its going incredibly slow though. I changed it to .00001 and it doesnt slow down at all. What do you think?

  7. #7
    Guest
    Hello,

    Yes I know I abouit the speed problem. I was looking for the other "Wait" function but I haven't been able to find it yet. Once I find it or someone else posts it here then I can show you how to use it instead of my little Do While Loop.

    We will get it right just hand in there,

    Best

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