There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop mac malware motherboard mouse network networking outlook 2007 power printer problem ram restart router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless wmp
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
*HELP* Visual Basic 6 *Beginner*


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
17-Oct-2004, 12:44 AM #1
*HELP* Visual Basic 6 *Beginner*
Hey guys,

I've been working with VB for a while now but I can't get loops to work with textbox's; is this possible?

Here's my code that won't work:

Private Sub cmdStart_Click()

a = 5
y = " test"

Do Until a = 1

Text1.Text = a & y

Loop

End Sub

----------------------

I'm trying to make it so it will count down in the textbox but it's not working.
I can get it to work with the picture box but something else interfered with that aswell.

Another question is with the text-to-speech component, is it possible to get it to speak whatever is printed into the picture box?

I know it's possible to get the text-to-speech to read whats in the textbox but I can't get the loops to work in the text box!!!

To get the speech to work with a textbox I have to type in...

"spkSpeak.speak text1.text"

Please help! thanks.
moebius's Avatar
Computer Specs
Senior Member with 1,765 posts.
 
Join Date: Oct 2003
Location: Dubai, UAE
Experience: sudo give me your money
17-Oct-2004, 08:03 AM #2
what do you get in the textbox when the loop runs? do you get anything at all? i dont have vb6 installed right now, so i might not be very good at helping you...
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
17-Oct-2004, 01:41 PM #3
Nothing shows up in the text box

Whereas if I perform the loop into the picturebox, it works...BUT I can't get the text to speech to read picturebox's.

My objective is to get the text to speech read what's in the text or picture box.

While in the text box or picture, it's looping numbers while I concatinate lyrics next to the looping variable.
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
17-Oct-2004, 02:39 PM #4
Well, I got the loop to work...

Next challenge is the text...what I want to do is have like a sing along caption going with the voice.

I have accomplished this with the picture box but it's going to be challenging with the textbox.

There's 2 ways I have thought of...

1: Having the lyrics to stay and the numbers to change.

ex. 5 bottles of beer on the wall,
5 bottles of beer,
you take one down, pass it around,
4 bottles of beer on the wall...

*Thing is! I can't get it to print text line by line even setting the properties to multiline(true)

Here's the code i've tried for this:

Other parts of the code
Text1.Text = i & a
Text1.Text = i & b
Text1.Text = c
Text1.Text = i & a
Other parts of the code

2: Having the line change as the song processes...
Ex. 5 bottles of beer on the wall
(Then that line erases)
5 bottles of beer!...
(Erases and keeps looping down)
Note: must create some sort of delay...I've gotten a delay to work with the picturebox but it wont work with the textbox!

I've created a fake variable to stall time:
(This is what i've put when I tried to make this program with a picbox)

Do until x = 10000000
x=x+1
Loop

This enabled me to set the time for when the numbers changed for the first example...
----------------------------------
Can anyone help or have any ideas? Would REALLY appreciate it!
moebius's Avatar
Computer Specs
Senior Member with 1,765 posts.
 
Join Date: Oct 2003
Location: Dubai, UAE
Experience: sudo give me your money
18-Oct-2004, 12:48 AM #5
you are doing something very wrong here... fake variable... delays... the whole thing. first of all vb6 isnt the right tool for what youre trying to make. id try with c++ or c#. vb6 was designed for database applications... inventory control and the like. the perfect way to do what youre trying to do, is to either:

1. create an activeX control. [this is not for begeinners]
OR
2. tap into the textbox control, intercept all windows commands to and from it, and customize it to your needs. you could do this, but its very tricky, and not quite easy.

anyways, to print stuff line by line:

text1.text = "line1" 'changes the text of text1 to line1
text1.text = text1.text & vbNewLine & "line2" 'adds a line after the text box's contents

got it?
__________________
Think for yourself
Question authority
Throughout human history, as our species has faced the frightening, terrorizing fact that we dont know who we are or where were going in this ocean of chaos, its been the authorities, the political, religious, educational authorities who attempted to comfort us by giving us order, rules, regulations, forming in our minds their view of reality. To think for yourself you must question authority and put yourself in a state of vulnerable open-mindedness.
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
18-Oct-2004, 01:12 AM #6
Or use a Timer and a counter in reverse and reset the text.
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
18-Oct-2004, 03:38 AM #7
thanks for the help, i'll try it out; I have to use vb6; it's a school project.


As for the timer and such; I've tried it with no luck...could you give me an example code to get it working with my objective?


Thanks a bunch guys
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
18-Oct-2004, 04:10 AM #8
I used a Label, but this will also work for a text box. The text changes color when the count changes. Put a timer on the form and set its interval to 7000 (7 seconds) as a start and see how that goes. You'll have to play with it to get the interval correct.

This has a command button to allow a pause and restart. Also to start again after it finishes. The timer is better than a loop for your needs. The code in the timer runs each time the interval has passed. Note the use of the Counter to decrement the Beer Bottles. (and its declaration)

The Sleep API is nice too. BUT use it sparingly because when the App is sleeping it will not respond to Windows Messages. Note, this sleeps once to keep the last bottle on screen for the same interval as the timer so the ending is smooth. Then the Label is cleared. You can skip that part if you like. I didn't really comment the code. But it is pretty straight forward. See if you understand and can explain it back.

Code:
Option Explicit
Private Counter As Integer
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()

If Command1.Caption = "Replay" Then
  Counter = 100
  Form1.Caption = "Form1"
  Timer1.Enabled = True
  Exit Sub
End If

If Timer1.Enabled = False Then
   Timer1.Enabled = True
   Call Timer1_Timer
   Command1.Caption = "Pause"
   Else: Timer1.Enabled = False
   Command1.Caption = "Resume"
End If
End Sub

Private Sub Form_Load()

  Counter = 100
  Call Timer1_Timer

End Sub

Private Sub Timer1_Timer()

Counter = Counter - 1

If Counter = 0 Then
   Form1.Caption = "The End"
   Sleep 7000
   Label1.Caption = ""
   Command1.Caption = "Replay"
   Timer1.Enabled = False
   Exit Sub
   
End If
  Label1.Caption = Space(3) & Counter & " bottles of beer on the wall" _
 & vbCrLf & Space(10) & Counter & " bottles of beer!..." _
 & vbCrLf & "You take one down, pass it around......" _
 & vbCrLf & Space(13) & Counter - 1 & " " & "bottles of beer on the wall!"
If Label1.ForeColor <> vbBlue Then
Label1.ForeColor = vbBlue
Else: Label1.ForeColor = Form1.ForeColor
End If

End Sub

Last edited by Mosaic1 : 18-Oct-2004 04:19 AM.
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
18-Oct-2004, 04:22 AM #9
PS Set Command1 's Caption to "Pause"
in its properties.
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
18-Oct-2004, 10:41 PM #10
OMG thank you SO much, i'm learning so much from what you've developed.

I love you.








Thanks! Let me configure it and apply the voice! I'll get back to you!
vigger's Avatar
Junior Member with 6 posts.
 
Join Date: Oct 2004
19-Oct-2004, 12:39 AM #11
Okay, so there's some stuff I don't completely understand...

No idea whats going on in there, lol a little too advanced.

1. Exit Sub<---what exactly is that for and why is it there since there's a "End Sub" on the bottom?

2. What does "Call" do? Does that switch the timer on?

3. Space(3) and vbCrLf ... what are they/what do they do?

4. Why Private Counter As Integer and not Dim private counter as integer? What's the function of private?

Thanks a bunch, sorry if these are stupid questions


BUT good news, I got it to work with the voice

I'll post my code tomorrow or so when I've fully developped/configured it.
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
19-Oct-2004, 06:34 PM #12
You're welcome. I have never worked with voice and it would be interesting to see how you have done it. Glad to hear you have it going.

Exit sub is there to prevent the rest of the code in the event from running. The event is cut short on purpose.

Play with it and see how it reacts. Comment out the Exit Sub. Set the timer's interval to 100 for the time being. This way you can get to the end fast. Go into the timer and comment out the Sleep 7000 line. See what happens when you press the button when it's labeled Replay. Then put everything back as it was and check the behavior again. You'll find that running all the code in the event makes a huge difference.
----------------------------------

When you enable a Timer, the code runs after the interval has elapsed. You would have to wait 7 seconds for the song to resume. If you called the timer then the code would run immediately but only once, because it has been disabled earlier. So you first enable the timer and then call it to get it to run right away and then continue.

Space(3) adds three spaces to the string. Instead of typing & " " & " " & " " it is a little shorthand.

vbcrlf ---- starts a new line.


I used large and bold font. I added a certain spacing to make the content easier to read. It's up to you how you would like your program to look. That's often more work than the code. Playing with it to make it look good.

Either Private or Dim will work. But I use Private because that's good form. If you have a chance, read up on scope ..... Private static public

Your questions are not stupid at all.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:13 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.