![]() |
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? |
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? |
Is that for VB.net? I am not getting it to work in VB 6
|
Quote:
|
It highlights Ref and says expected list or separator.
|
Quote:
|
Now when calling the function I get a data mismatch. My Array is defined as varaint.
|
Quote:
Dim varArray(1 To 5, 1 To 5) As Variant |
Awful nice of VPI to do your homework for you. :)
|
Quote:
Code:
Option Explicit |
Quote:
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. |
Quote:
Thx for your comment! |
Quote:
Well, you could always find more things to whine about. |
God, I love VB!
|
Quote:
I just tried this out and it worked: Code:
Dim mstrPatients(1 To 50, 1 To 6) As Variant |
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. |
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? |
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.
|
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.
|
| All times are GMT -5. The time now is 12:13 AM. |
Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.