Front Office Football Central

Front Office Football Central (https://forums.operationsports.com/fofc//index.php)
-   FOFC Archive (https://forums.operationsports.com/fofc//forumdisplay.php?f=27)
-   -   VB Help (https://forums.operationsports.com/fofc//showthread.php?t=32844)

GoldenEagle 12-07-2004 10:54 AM

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?

VPI97 12-07-2004 11:05 AM

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?

GoldenEagle 12-07-2004 11:11 AM

Is that for VB.net? I am not getting it to work in VB 6

VPI97 12-07-2004 11:19 AM

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?

GoldenEagle 12-07-2004 11:21 AM

It highlights Ref and says expected list or separator.

VPI97 12-07-2004 11:24 AM

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.

GoldenEagle 12-07-2004 11:26 AM

Now when calling the function I get a data mismatch. My Array is defined as varaint.

VPI97 12-07-2004 11:28 AM

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

primelord 12-07-2004 11:28 AM

Awful nice of VPI to do your homework for you. :)

GoldenEagle 12-07-2004 11:31 AM

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
 


GoldenEagle 12-07-2004 11:33 AM

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.

GoldenEagle 12-07-2004 11:36 AM

Quote:

Originally Posted by RPI-Fan
Well, you could always find more things to whine about.


Thx for your comment!

RPI-Fan 12-07-2004 11:36 AM

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.

CraigSca 12-07-2004 11:36 AM

God, I love VB!

VPI97 12-07-2004 11:44 AM

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


GoldenEagle 12-07-2004 01:00 PM

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.

Mr. Wednesday 12-07-2004 03:38 PM

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?

GoldenEagle 12-07-2004 04:10 PM

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.

Mr. Wednesday 12-07-2004 07:32 PM

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.