Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,572 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,931 people online right now. Registration is fast and FREE... Join Now!




Distance Traveled

2 Pages V  1 2 >  
Reply to this topicStart new topic

Distance Traveled

liko
10 May, 2008 - 01:40 AM
Post #1

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

I need to make a code that just simple loops and prints on the input. Example you will put the speed your going and than the time if you put 50 miles per gallon it will just double it so it would be 100. Any help would be appreciated i did some what this for starters, but doesn't work.
CODE
Private Sub cmdRunDemo_Click()
    Dim sngTotal As Single
    Dim intNumScores As Integer
    Dim sngAverage As Single
    Dim strInput As String
    Dim intCount As Integer
        
    strInput = InputBox("Vechile speed?", _
                        "Enter a Value")
    strInput = InputBox("time?", _
                       "Enter a Value")
                        
  
    Do Until strInput <= 1  'intCount
        strInput = InputBox("Enter Value " & _
                             FormatNumber(intCount, 0), "")
        sngTotal = sngprint + Val(strprint)
        intCount = intCount + Number
    Loop
    sngAverage = sngTotal
  For k% = 1 To intCount

Next

End Sub

User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 10:05 AM
Post #2

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Speed? 50 miles per gallon? Which one is it? *scratches head*

I'd tell you how to do your example but your code tells me there's something more going on, so I don't know if that would help you very much.

You're using the same string variable to hold the data from multiple input boxes. That means the stuff that the string holds is being overwritten before you're even doing anything with it. Use a different string for each input box. Also it looks like you didn't declare "strprint".

I'd help more than this but I'm not sure what you're trying to do. Please post again with more information.

This post has been edited by Zhalix: 10 May, 2008 - 10:06 AM
User is offlineProfile CardPM
+Quote Post

liko
RE: Distance Traveled
10 May, 2008 - 02:19 PM
Post #3

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

QUOTE(Zhalix @ 10 May, 2008 - 11:05 AM) *

Speed? 50 miles per gallon? Which one is it? *scratches head*

I'd tell you how to do your example but your code tells me there's something more going on, so I don't know if that would help you very much.

You're using the same string variable to hold the data from multiple input boxes. That means the stuff that the string holds is being overwritten before you're even doing anything with it. Use a different string for each input box. Also it looks like you didn't declare "strprint".

I'd help more than this but I'm not sure what you're trying to do. Please post again with more information.

Ahh sorry for being confusing. I was trying to use some previous codes, but it seems i confused it more. All it has to do is inputting the number of miles your gonna go and type the hour and it will print the miles you went and the hours you went example what it would show on print.

Vehicle speed 40 MPH
Time Traveled 3 hours
Hours Distance traveled

1 40
2 80
3 120

Total Distance 120

i just don't know how to do it or what to use i was messing with codes to help me.
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 03:36 PM
Post #4

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
I don't think your explanatory paragraph describes what the example shows, but I'll show you how to do both. I'm not sure what you mean by print either. I hope you just mean putting it into a textbox or something, which is what I'll do in the example.


Your explanatory paragraph:

CODE

Private Sub cmdCalculate_Click()

Dim VehicleSpeed As Integer
Dim TravelTime As Long
Dim Miles As Integer

Miles = InputBox("Enter Miles:")
VehicleSpeed = InputBox("Enter Speed:")
TravelTime = VehicleSpeed / Miles

txtInfo.Text = "Miles: " & Miles & vbNewLine & "Hours: " & TravelTime

End Sub


Your example:

CODE

Private Sub cmdCalculate_Click()

Dim TravelTime As Integer
Dim VehicleSpeed As Integer
Dim Miles As Integer

VehicleSpeed = InputBox("Enter Speed:")
TravelTime = InputBox("Enter Time Traveled:")
Miles = TravelTime * VehicleSpeed

txtInfo.Text = "Hours: " & TravelTime & vbNewLine  & "Miles: " & Miles

End Sub


This post has been edited by Zhalix: 10 May, 2008 - 03:45 PM
User is offlineProfile CardPM
+Quote Post

liko
RE: Distance Traveled
10 May, 2008 - 03:58 PM
Post #5

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

Ya my code was really wrong. This is my first programming class i am almost done thank god i am not majoring in computers programming i didn't know it was this hard. Also well when i do the distance it gets it but the hours it shows it as 0 i don't know what to do there anime2.gif. Also about the print it just prints instead of showing text so i just changed the text to print and shows it just not the calculation correctly since it shows 0 on hours when i put 1 or 2 or any other number.

This post has been edited by liko: 10 May, 2008 - 04:03 PM
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 04:05 PM
Post #6

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Ah, see, I've never used Print for anything so I wasn't sure if you really meant that. You could use Print, it would work. And if you wanted to print each value after each inputbox, just put the print command after each inputbox.

As for making an inputbox have the default value of 55, this would work:

CODE

InputBox("Whatever", "Whatever", "55")


EDIT:

Ah you modified your post while I was writing mine.

Please tell me your problem again more clearly and also provide me with the code you're using.

This post has been edited by Zhalix: 10 May, 2008 - 04:09 PM
User is offlineProfile CardPM
+Quote Post

liko
RE: Distance Traveled
10 May, 2008 - 04:13 PM
Post #7

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

QUOTE(Zhalix @ 10 May, 2008 - 05:05 PM) *

Ah, see, I've never used Print for anything so I wasn't sure if you really meant that. You could use Print, it would work. And if you wanted to print each value after each inputbox, just put the print command after each inputbox.

As for making an inputbox have the default value of 55, this would work:

CODE

InputBox("Whatever", "Whatever", "55")


EDIT:

Ah you modified your post while I was writing mine.

Please tell me your problem again more clearly and also provide me with the code you're using.

yes sorry for just modiefied but actually the second code worked and i really thank you i was making it show print all i had to do is take of the text since the teacher wants it to show text this is what i got. What i need is for the program to look exactly like this when you put the digits?

Vehicle speed 40 MPH
Time traveled 3 hours
Hour Distance Traveled

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

1 40
2 80
3 120
Total Distance 120

What i got and was sorta modefiing is this i don't get it exactly like that yet. It works though the program biggrin.gif

CODE

Private Sub cmdRunDemo_Click()



Dim TravelTime As Integer
Dim VehicleSpeed As Integer
Dim Miles As Integer

VehicleSpeed = InputBox("Enter Speed:")
TravelTime = InputBox("Enter Time Traveled:")
Miles = TravelTime * VehicleSpeed

Print "Vehicle Speed"; Miles; "MPH"
Print "Time traveled"; TravelTime; "Hours"
Print "Hour Distance Traveled"



Print "Hours: " & TravelTime & vbNewLine & "Miles: " & Miles



End Sub



Edit on the when you input the speed i put inputbox ("55") it would put an extra box to input since i want it when i start the program to show 55 as default highlighted and i guess you put what you want. thats what the teacher asked thats why anime2.gif

This post has been edited by liko: 10 May, 2008 - 04:16 PM
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 04:17 PM
Post #8

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
I'm not sure I understand the last part, the part you put it. Could you say it again more clearly?

This post has been edited by Zhalix: 10 May, 2008 - 04:21 PM
User is offlineProfile CardPM
+Quote Post

liko
RE: Distance Traveled
10 May, 2008 - 04:19 PM
Post #9

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

QUOTE(Zhalix @ 10 May, 2008 - 05:17 PM) *

So do you need any more help?

Please a little more i don't know to make it like how i showed you exactly ilke that it shows the numbers but not like in that order also. How can you show it to show
1 40
2 80
3 120
like showing it how it doubles on print.
I wanted to show what i had to be easier to understand since i know i am so confusing.
IPB Image

This post has been edited by liko: 10 May, 2008 - 04:26 PM
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 04:28 PM
Post #10

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
To show how it adds more each time, this code should work.
I'm not sure how you want to implement this into your program,
but I figure this'll help either way.

CODE

Dim TravelTime As Integer
Dim VehicleSpeed As Integer

VehicleSpeed = InputBox("Enter Speed:")
TravelTime = InputBox("Enter Time Traveled:")

For i = 1 To TravelTime

    Print i & " " & i * VehicleSpeed

Next i


By the way, you might wanna downsize that image.. it's HUGE.

This post has been edited by Zhalix: 10 May, 2008 - 04:35 PM
User is offlineProfile CardPM
+Quote Post

liko
RE: Distance Traveled
10 May, 2008 - 04:36 PM
Post #11

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

gona try that i will show you how it looks in the book i took a picture i know its confusing but thats how its suppose to look.
IPB Image
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Distance Traveled
10 May, 2008 - 04:39 PM
Post #12

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Ohh, okay. I'll make it output that EXACTLY.
Give me a moment to make the code and I'll modify this post to put it in.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:58PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month