Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 12-07-2004, 11:54 AM   #1
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
VB Help

I have to write the code for the following for an assignment. The book is no help and every thing I have tried so far does not work. Here is what I have to do:

Create a genreal procedure that displays the current patient. Use the Value property of the scrollbar hsbPNumber as the array subscript to place the patient information into the corresponding text boxes and labels on the form. The name of the objects corresponds to the column, as follows:

lblPatientNumber Column 1, value of the scroll bar hsbPNumber
txtPatientName Column 2
txtDOB column 3
txtDoctorName Column 4
txtDiagnosis Column 5
txtDateAdmitted Column 6, time the patient was admitted

Any ideas?
__________________
Xbox 360 Gamer Tag: GoldenEagle014

GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:05 PM   #2
VPI97
Hokie, Hokie, Hokie, Hi
 
Join Date: Mar 2001
Location: Kennesaw, GA
I'm assuming that you're talking about a multi-dimensional array of data, right?

Call PopulateData(patientArray)

Function PopulateData(By Ref pData() as Variant)
iRow = hsbPNumber.Value

lblPatientNumber.caption = iRow
txtPatientName = pData(iRow , 2)
txtDOB = pData(iRow , 3)
txtDoctorName = pData(iRow , 4)
txtDiagnosis = pData(iRow , 5)
txtDateAdmitted = pData(iRow , 6)
End Function

Does that work?
VPI97 is offline   Reply With Quote
Old 12-07-2004, 12:11 PM   #3
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
Is that for VB.net? I am not getting it to work in VB 6
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:19 PM   #4
VPI97
Hokie, Hokie, Hokie, Hi
 
Join Date: Mar 2001
Location: Kennesaw, GA
Quote:
Originally Posted by GoldenEagle
Is that for VB.net? I am not getting it to work in VB 6
What error is it giving you?
VPI97 is offline   Reply With Quote
Old 12-07-2004, 12:21 PM   #5
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
It highlights Ref and says expected list or separator.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:24 PM   #6
VPI97
Hokie, Hokie, Hokie, Hi
 
Join Date: Mar 2001
Location: Kennesaw, GA
Quote:
Originally Posted by GoldenEagle
It highlights Ref and says expected list or separator.
My bad...it should be 'ByRef' instead of 'By Ref'...no space.
VPI97 is offline   Reply With Quote
Old 12-07-2004, 12:26 PM   #7
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
Now when calling the function I get a data mismatch. My Array is defined as varaint.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:28 PM   #8
VPI97
Hokie, Hokie, Hokie, Hi
 
Join Date: Mar 2001
Location: Kennesaw, GA
Quote:
Originally Posted by GoldenEagle
Now when calling the function I get a data mismatch. My Array is defined as varaint.
Do you have it setup as a multi-dimensional array? i.e.:
Dim varArray(1 To 5, 1 To 5) As Variant
VPI97 is offline   Reply With Quote
Old 12-07-2004, 12:28 PM   #9
primelord
Pro Rookie
 
Join Date: Oct 2000
Awful nice of VPI to do your homework for you.
primelord is offline   Reply With Quote
Old 12-07-2004, 12:31 PM   #10
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
Quote:
Originally Posted by VPI97
Do you have it setup as a multi-dimensional array? i.e.:
Dim varArray(1 To 5, 1 To 5) As Variant
Code:
Option Explicit Dim mstrPatients(1 To 50, 1 To 6) As Variant Private Sub PopulateData(ByRef pData() As Variant) iRow = hsbPNumber.Value lblPatientNumber.Caption = iRow txtPatientName = pData(iRow, 2) txtDOB = pData(iRow, 3) txtDoctorName = pData(iRow, 4) txtDiagnosis = pData(iRow, 5) txtDateAdmitted = pData(iRow, 6) End Sub Private Sub cmdExit_Click() Unload Me End Sub Private Sub Command2_Click() End Sub Private Sub cmdWrite_Click() Dim pintCurrentItem As Integer Open "C:\1076-5\CHAPTER.07\Exercise\Patient.txt" For Append As #1 Close #1 End Sub Private Sub cmdPrint_Click() Dim pintRow As Integer Dim pintColumn As Integer For pintRow = 1 To 50 If mstrPatients(pintRow, 1) = "" Then Exit For Else For pintRowColumn = 1 To 6 Printer.Print mstrPatients(pintRow, pintColumn) & Chr(vbKeySpace) Next Printer.Print End If Next Printer.EndDoc End Sub Private Sub Form_Load() Dim psngPatientNo As String Dim pstrPatientName As String Dim psngPatientDOB As String Dim pstrDoctorName As String Dim pstrDiagnosis As String Dim psngDateAdmitted As String Dim pintRow As Integer pintRow = 1 Open "C:\1076-5\CHAPTER.07\Exercise\Patient.txt" For Input As #1 Do Until EOF(1) = True Input #1, psngPatientNo, pstrPatientName, psngPatientDOB, _ pstrDoctorName, pstrDiagnosis, psngDateAdmitted mstrPatients(pintRow, 1) = psngPatientNo mstrPatients(pintRow, 2) = pstrPatientName mstrPatients(pintRow, 3) = psngPatientDOB mstrPatients(pintRow, 4) = pstrDoctorName mstrPatients(pintRow, 5) = pstrDiagnosis mstrPatients(pintRow, 6) = psngDateAdmitted pintRow = pintRow + 1 Loop Close #1 PopulateData (mstrPatients) End Sub
__________________
Xbox 360 Gamer Tag: GoldenEagle014

Last edited by GoldenEagle : 12-07-2004 at 12:32 PM.
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:33 PM   #11
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
Quote:
Originally Posted by primelord
Awful nice of VPI to do your homework for you.

Where else can you turn when the book does not answer anyting (this is the wiorst textbox I have ever used) and your professor has cancelled class the past four meetings but still expects you to turn in your homework on time.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:36 PM   #12
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
Quote:
Originally Posted by RPI-Fan
Well, you could always find more things to whine about.

Thx for your comment!
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 12:36 PM   #13
RPI-Fan
Pro Starter
 
Join Date: Nov 2000
Location: Troy, NY
Quote:
Originally Posted by GoldenEagle
Where else can you turn when the book does not answer anyting (this is the wiorst textbox I have ever used) and your professor has cancelled class the past four meetings but still expects you to turn in your homework on time.

Well, you could always find more things to whine about.
__________________
Quis custodiets ipsos custodes?
RPI-Fan is offline   Reply With Quote
Old 12-07-2004, 12:36 PM   #14
CraigSca
Pro Starter
 
Join Date: Jul 2001
Location: Not Delaware - hurray!
God, I love VB!
__________________
She loves you, yeah, yeah, yeah, yeah!
She loves you, yeah!
how do you know?
how do you know?

CraigSca is offline   Reply With Quote
Old 12-07-2004, 12:44 PM   #15
VPI97
Hokie, Hokie, Hokie, Hi
 
Join Date: Mar 2001
Location: Kennesaw, GA
Quote:
Originally Posted by GoldenEagle
Now when calling the function I get a data mismatch. My Array is defined as varaint.
Maybe something with your data?

I just tried this out and it worked:
Code:
Dim mstrPatients(1 To 50, 1 To 6) As Variant Private Sub Form_Load() Dim psngPatientNo As String Dim pstrPatientName As String Dim psngPatientDOB As String Dim pstrDoctorName As String Dim pstrDiagnosis As String Dim psngDateAdmitted As String Dim pintRow As Integer pintRow = 1 Do Until pintRow > 40 mstrPatients(pintRow, 1) = "pintRow" & CStr(pintRow) mstrPatients(pintRow, 2) = "pintRow" & CStr(pintRow) mstrPatients(pintRow, 3) = "pintRow" & CStr(pintRow) mstrPatients(pintRow, 4) = "pintRow" & CStr(pintRow) mstrPatients(pintRow, 5) = "pintRow" & CStr(pintRow) mstrPatients(pintRow, 6) = "pintRow" & CStr(pintRow) pintRow = pintRow + 1 Loop Close #1 Call PopulateData(mstrPatients) End Sub Public Sub PopulateData(ByRef pData() As Variant) iRow = hsbPNumber.Value Label1.Caption = iRow Text1 = pData(iRow, 2) Text2 = pData(iRow, 3) Text3 = pData(iRow, 4) Text4 = pData(iRow, 5) Text5 = pData(iRow, 6) End Sub
VPI97 is offline   Reply With Quote
Old 12-07-2004, 02:00 PM   #16
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
I just went in turned in and the professor told me that he was not going to count in since so many people were having problems with it. That was six hours of my life watsed when I could have studying for my two big finals on Wed.

VPI, thanks for your help.

Craig, I hate it. I pefer C++ over VB any day of the week.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 04:38 PM   #17
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Eh, outside of generics (which are very cool) there's very little that you can do in C++ that is inconvenient to do in VB. It's just a matter of learning the syntax. Part of the problem here is that IMO they're asking you to do something in a suboptimal way. You shouldn't be pulling this data out of an untyped array like that, it's horrid design. You should encapsulate the file processing in one area and then access the data through some kind of interface.

If I were doing something like this, I'd do either a class or module to read the data in and use a class or type to hold it. I wouldn't use a text file for a database, I'd use a real database, probably Access format for a toy problem like this one.

Part of the problem with getting the code above to work, I'd imagine, is confusion over variable typing. In the one case, you've got an array of Variants. In the other, you've got a Variant that contains an array. Unfortunately, these are not the same thing.

In the full listing, it looks OK, you declare an array of variants and then the sub accepts an array of variants as an argument. If this doesn't work, what error are you getting?
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 12-07-2004, 05:10 PM   #18
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
I figured it out. It just needed a little tweaking. I agree that the program was very flawed. I was thinking if I was doing this in C++, I would do this and do that. Part of my problem with VB is that I dfo stuff that would work in C++ but not VB. I think its probably best to keep the two seperate.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 12-07-2004, 08:32 PM   #19
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
It depends what you're trying to do, and what style of C++ you usually program. If you tend more toward procedural and generic style C++, you often won't need to adjust your thinking all that much to work in VB.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 02:31 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.