
|
View Full Version : Visual Basic problem... help me please
Adi-2k1 01-14-2002, 08:17 PM Hello all,
I'm trying to make a vb application but I ran into some trouble.
I'm trying to make a simple application that has two labels stacked under one another and two buttons besides the labels that say "Start" and "Done." The top label will only have instructions in it, so it's no big deal but the 2nd label, which would be underneath the first label, should display the answer which I'm about to explain.
When the user clicks "Start" on the application, it should pop up 5 Input boxed one after another asking the user how many visitors they recieve each day on their website. When the first input box pops up the user types in the number of visitors he got that day, then after he pushed "OK" another input box pops up and asks him the same question again. This goes on for five input boxed, asking the user for the visitor for 5 days of visitors that came to their site. When the user is done with putting in all the information, and hits "OK" for the last time, it should give him the average number of hits that he recieves for each day out of the five days that he entered. This answer should be displayed in the lower label.
Now, here is the code that I tried to use to make this application work, but I'm 100% that I messed up alot so I'm asking some of you to modify it and if possible make my application work. Here goes my code:
-------------------------------------------------------------------------------
Option Explicit
_________________________
Private Sub cmdStart_Click()
Dim int1 As Integer, int2 As Integer, int3 As Integer, int4 As Integer, int5 As Integer, int6 As Integer
Dim intC As Integer
Const intD As Integer = 5
lblAverage.Caption = ""
Do
Loop While int4 = InputBox("Enter Average Daily Attendence", "Attendence")
int1 = int1 + int4
Do
Loop While int3 = InputBox("Enter Average Daily Attendence", "Attendence")
int1 = int1 + int3
Do
Loop While int2 = InputBox("Enter Average Daily Attendence", "Attendence")
int1 = int1 + int2
Do
Loop While int5 = InputBox("Enter Average Daily Attendence", "Attendence")
int1 = int1 + int5
Do
Loop While int6 = InputBox("Enter Average Daily Attendence", "Attendence")
int1 = int1 + int6
lblAverage = int4 + int3 + int2 + int5 + int6 / intD
End Sub
_________________________
Private Sub cmdDone_click()
Unload Me
End Sub
_________________________
-------------------------------------------------------------------------------
OK, that would be the code that I have for right now. It's not totally done, because I'm stuck and it looks totally wrong. If I'm using a wrong method please correct me.
I will appriciate all the help that I can get ;)
Shawn (GEcom) 01-14-2002, 09:15 PM Here you go. This should work :)
Private Sub cmdStart_Click()
'Make Declarations
Dim int1, int2, int3, int4, int5 As Integer
Const intD As Integer = 5
'Reset Label Caption
lblAverage.Caption = ""
'Load Inputboxes
int1 = Int(InputBox("Enter Average Daily Attendence 1", "Attendence"))
int2 = Int(InputBox("Enter Average Daily Attendence 2", "Attendence"))
int3 = Int(InputBox("Enter Average Daily Attendence 3", "Attendence"))
int4 = Int(InputBox("Enter Average Daily Attendence 4", "Attendence"))
int5 = Int(InputBox("Enter Average Daily Attendence 5", "Attendence"))
'Calculate Average
lblAverage.Caption = (int1 + int2 + int3 + int4 + int5) / intD
End Sub
Private Sub cmdDone_click()
'Unload the form
Unload Me
End Sub
Adi-2k1 01-14-2002, 09:36 PM Sweet, would that do it and make the whole application work? If so, is there any way someone could make that quickly with vB and upload it to a site so that I can test it? I can't, because the only PC that I have that has vB is the computer in school and now I'm at home.
Thank you very much for all the help... :)
Shawn (GEcom) 01-14-2002, 10:10 PM Here you go. The project and compiled exe files are included in the zip
Adi-2k1 01-14-2002, 10:38 PM Hey,
Thanx to all of you for helping. Now I got this straight and hope that it will help me. :)
DougBTX 01-15-2002, 01:38 PM I've not been in VB much recently, but felt like throwing this in:
Option Explicit
Private Sub cmdStart_Click()
'number of inputs, could be set by a spin button+textBox on your form
Const intD As Integer = 5
'Make Declarations
Dim intX() As Integer
Dim iTotal As Integer
Dim i As Integer
'Define array
ReDim intX(intD - 1) As Integer
'Reset Label Caption
lblAverage.Caption = ""
'Load Inputboxes
For i = 0 To intD - 1
iTotal = iTotal + Int(InputBox("Enter Average Daily Attendence " & (i + 1), "Attendence"))
Next i
'Calculate Average
lblAverage.Caption = (iTotal) / intD
End Sub
Private Sub cmdDone_click()
'Unload the form
Unload Me
End Sub
sorry its not fancy colours :stickout
Later,
Douglas
DjPaj 01-15-2002, 04:15 PM VB=:puke:
Sorry, had bad experiences with VB, learned it, found it was easy to learn, then discovered no one wants a VB programmer anymore. Soooooooo I learned JAVA :D
DougBTX 01-15-2002, 06:27 PM Originally posted by DjPaj
JAVA :D
JAVA?!?!?!?!?
Who needs that? ;)
I'm a Delphi man now, but want to take a look at C# (the guy who did the main organisational stuff for Dlephi and C# are the same person (something like that anyway :confused: ))
Later,
Douglas
platinum 01-16-2002, 08:44 AM If ya know VBscript, you can always start coding ASP :D Thats a good choice, escpecially with asp.net being released...
Adi-2k1 01-16-2002, 07:01 PM Ahh, I forgot to tell you all that the code needed to have a LOOP in it so I only got part of the application right and got a 69 in school on my programming exam. :bawling:
Let's hope I do better on the next quiz.
ckpeter 01-16-2002, 07:24 PM I don't think its right to let other people do your homework.
Peter
MattF 01-16-2002, 07:51 PM C# is very interesting, very similar to java, more aimed at window users, and has more features directly present in the core classes. I'll explain more tomorrow. :)
Adi-2k1 01-16-2002, 08:47 PM Originally posted by ckpeter
I don't think its right to let other people do your homework.
Peter
I didn't know how to solve the application and asked for help.
What was I supposed to do? I had to review for the quiz and this was my only way since I don't have a VB book or program here at home.
DougBTX 01-17-2002, 12:47 PM Originally posted by Adi-2k1
I didn't know how to solve the application and asked for help.
What was I supposed to do? I had to review for the quiz and this was my only way since I don't have a VB book or program here at home.
The help files probably have all you need btw...and there are also lots of sites about VB...and my example had a loop in it anyway :D
Later,
Douglas
VhatDaFruit 01-18-2002, 05:07 AM VB is sux. It definitely not good to start to learn coding through VB. You'll get bad habits that will stay with you for life!
VhatDaFruit 01-18-2002, 05:09 AM I'm a Delphi man now
Delphi is sux. It's for cheapos who can't afford VB (no offence) :D
platinum 01-18-2002, 05:46 AM Originally posted by VhatDaFruit
VB is sux. It definitely not good to start to learn coding through VB. You'll get bad habits that will stay with you for life!
HA!
nope, actually Visual Basic is a core componet of almost all microsofts products (including access, word, etc) and can be used to program ASP's with.... in fact, it is a very easy, object-based language to learn, not to mention the obvious benifits of speedy software creation in Visual Basic, what could be easier if you need a quick program. I have v.6 enterprise edition. But i'll be anxious to see what v.7 looks like...
I'll agree that C++ is a much more powerful language though, just depends on what you are using it for I guess.... :)
(Borland Delphi is somthing i've never played with much, is it really that bad? I was of the opinion it was quite similar *in looks anyway* to Visual Basic).
DougBTX 01-18-2002, 12:24 PM Originally posted by VhatDaFruit
Delphi is sux. It's for cheapos who can't afford VB (no offence) :D
I have VB6 Pro AND Delphi 6 :D
Which do you think I use the most? ;)
(I'll give you a clue: I've uninstalled VB6 :D )
Originally posted by platinum
Borland Delphi is somthing i've never played with much, is it really that bad?
It takes more programming knowledge to use Delphi, because it does not take you by the hand all the way through making your programs. It is so much calmer to program away, and then get a list of your errors when you compile (which are a doubble click away from the line in your code) compared to the method VB uses...you press enter, or click on another line, and up pops an eror message "your if statment is invalid!!" and your code glows red..arg! Its annoying!!
When you first start using Delphi, the language can seem pritty weak, but then I realised that all the hacks I was trying to use in Delphi, which you have to use to do *anything* in VB, were all catered for, more easily I should point out, than in VB.
Try playing around with DCs in VB, and it's just a mess. Linking into the APIs with with declare statments...arg! Just load up a TCanvas and your away in Delphi. It even has an HWid property if you really *have* to use the APIs.
If there was one thing that would make the differance between VB and Delphi, it would have to be inheritance. Makes life soo much easier.
Also your point about VBA being in most of MS's products, its there becaue it is, as the name sort of implies, "Basic". It's a simple fact that people writing word documents don't want to have to learn a programming language....
About VB damaging potential programmers for life...it's just that VB has very little structure, while Delphi has a strong, but flexable one. A good example is declaring variables:
In VB, you can have Dims anywhere you want, but in Delphi decleratoins are separate from the code itself. And you don't have to turn on Option Explicit either...
Finally, for quick programs, I also prefer Delphi. I have made a small note taking program which sits in a toolbar at the bottom right of my display. I originally made it in VB, but once I discovered Delphi it didn't take me long to realise I needed an upgrade :)
And finally, the nail in the coffin for VB for me, is the runtimes issue. Sorry, but when it comes down to it, to me it just feels like slack programing on the part of MS.
I'm allways open to other things, and as I say, C# (the bigger brother of the cut down / encapsulated non compatable version ov VB.NET) looks interesting..anyone know where I can get a trial from?
ckpeter 01-18-2002, 03:25 PM Well, you guys should take a look at microsoft's .Net framework. The new Visual Studio.Net will change all that you are discussing. (That's 7.0 for those of you who don't know)
Because of the Common Language Runtime and the .Net Framework, VB will be just as powerful as VC, VC#, etc... The differences in language will simply be a matter of taste.
Well, there is just too much to list, if you are interested, just go on to microsoft.com and read about .Net.
Peter
DougBTX 01-18-2002, 04:04 PM Originally posted by ckpeter
The differences in language will simply be a matter of taste.
Not exactly, but that's the idea...(VB with compatability for older versions etc..)
Think that must have been my longest post :cool: and not even about anything to do with hosting :D
Later,
Douglas
platinum 01-19-2002, 11:26 PM Originally posted by ckpeter
Well, you guys should take a look at microsoft's .Net framework. The new Visual Studio.Net will change all that you are discussing. (That's 7.0 for those of you who don't know)
Because of the Common Language Runtime and the .Net Framework, VB will be just as powerful as VC, VC#, etc... The differences in language will simply be a matter of taste.
Well, there is just too much to list, if you are interested, just go on to microsoft.com and read about .Net.
Peter
I'm waiting for the stable version to be released :D
As well as for all of the hosts to implemtent asp.net...
Adi-2k1 01-20-2002, 02:31 AM Whoa, this conversation about me asking for some code has really developed into a real chat about vb. ;)
|