lawlaw81 07-21-2003, 07:59 AM Hi:
I need to input data from a text file to a 2 dimension array and show it in a picturebox like a report...But I don't know how to populate the array and display in the picturebox!!!
the report that I should create must have 6 columns and 5 rows...
once I have to report displayed in the picturebox, I have to make sure that the user can't put the same "product code" into the array, what should I do?
Please save me:~~ it is for my final project!!
Thanks a lot!!!
Tweakish 07-21-2003, 09:16 AM I need to input data from a text file to a 2 dimension array and show it in a picturebox like a report...But I don't know how to populate the array and display in the picturebox!!!
something like this
Open filepath for input as #1
For tempY = 1 To maxY
Line Input #1, tempStr
For tempX = 1 To maxX
tempChar = Mid(tempStr, tempX, 1)
Array(tempX, tempY) = tempChar
Next
Next
close #1
You said to display the code in a picturebox(singular), which I'm not sure how to do. Multiple pictureboxes would be easy, but I'll leave that to you.
I have to make sure that the user can't put the same "product code" into the array, what should I do?
for x = 1 to whatever
for y = 1 to whatever
if array(x,y) = productcode then
msgbox "Get yer OWN product code!"
end if
next
next
passel 07-21-2003, 09:51 AM Hi:
I need to input data from a text file to a 2 dimension array and show it in a picturebox like a report...But I don't know how to populate the array and display in the picturebox!!!
the report that I should create must have 6 columns and 5 rows...
once I have to report displayed in the picturebox, I have to make sure that the user can't put the same "product code" into the array, what should I do?
Please save me:~~ it is for my final project!!
Thanks a lot!!!
Depending on the size of the data, if it's small you may be able to
get away with this.
Picture1.Cls
For i = 1 to 5
for j = 1 to 6
Picture1.print Data(i,j), 'print string and add Tab
next
Picture1.print 'Carriage Return/ Line Feed to the next line
next
You could use print Data(i,j),, to put two tabs between columns, but that's
pretty spread out.
If you need more control over the spacing of the columns then,
use this code. The ";" suppress cr/lf so text would be appended.
We set Picture1.CurrentX to j*50 to make the columns 50 pixels wide
Picture1.Cls
Picture1.ScaleMode = vbPixels
For i = 1 to 5
for j = 1 to 6
Picture1.print Data(i,j); 'print string leaving cursor at end of string
Picture1.CurrentX = j*50
next
Picture1.print 'Carriage Return/ Line Feed to the next line
next
You could have a table Column_Offset(1 to 6) to hold the values you
set CurrentX to, if you want various width columns.
After you've printed your data, CurrentY will be below the last line printed
so you could do something like this to put lines between your columns.
Ybottom = Picture1.CurrentY
for i = 1 to 5:
Picture1.Line(i*50-5,0) - (i*50-5,Ybottom)
next
How you populate the array depends on the format of the data in the file, ie are the fields defined by fixed spacing, separated by spaces, commas, tabs, or some other character. Are there spaces in your field.
Are you using VB 5 or VB 6 (VB 6 as a split function to aid extracting fields from a string, this would have to be simulated in VB 5). You will have to provide a sample of the contents of the file, to get specific help.
lawlaw81 07-21-2003, 10:16 AM Thanks for u guys replies!!it is very helpful!!
here is the sample of my data:
Product code Description Supplier Cost Quantity Delete Flag
L666 Surge Protector Pc King 3.30 160 N
M013 Ms Mouse Memory-rex 23.22 28 N
H013 20GB Hard Drisk Micro Shop 190.00 18 N
and so on....
If i don't want the user to put in the same product code in the array, what should I do?I know I have to search in the array....
Thanks again
lawlaw81 07-21-2003, 10:19 AM Do I have to declare the array in the module? or somewhere else?
passel 07-21-2003, 10:41 AM Do I have to declare the array in the module? or somewhere else?
It looks like the data is separated by tabs, you can use split to divide
the data. I don't have VB6 here so, you will have to look up the description.
In general,
'if you are going to be adding records then the dimensions should probably be higher then 5,6, perhaps 10,6 for your project?
'Should be declared in the declarations area of your form, or in a module.
Dim data_rec(5, 6), p As Integer
Dim rec_cnt As Integer
Open "filename" For Input As #1
While Not EOF(1)
rec_cnt = rec_cnt + 1
Line Input #1, a$
'Split a$ into an array, using 'tab' as your delimiter
For i = 1 To 6
Data(rec_cnt, i) = splitarry(i) 'or i + 1 if zero based
Next
Wend
'Look for a duplicate entry, along the lines of.
Dim not_allowed As Boolean
For i = 1 To rec_cnt
If Data(i, 1) = InputID Then
not_allowed = True
Exit For
End If
Next
If not_allowed Then
'Give an error message
Else
rec_cnt = rec_cnt + 1
'add a new record?
End If
lawlaw81 07-21-2003, 10:52 AM just wanna show u guys the requirements, so if any ideas come up, it will be helpful!!!:)
Preliminary:
Using Windows notepad, create a sequential dish file using the data as described (previous Thread)
Main Program:
Your program is to act as an interactive file maintenance system for the Inventory master file that you created previously
In order to efficiently process the updates, as an initial task, all of the master file records should be read into a 2-dimensional array.To allow for the addition of new records, choose and appropiate size for the array.
The following are the activities that your program must perform:
-CHANGE any of the following fields:Description, Supplier, Cost,
Quantity. Prevent a Product Code Change
-DELETE an existing record by setting the Delte Flag to "Y"
-ADD a new records. (Replace records with the same key that have
been previously deleted)
-DISPLAY(in a picture box) the current records in your array whenever
desired.This will enable u to verify that modifications were
performed correctly
-END the program
your program must be able to identify the following types of errors:
-INVALID ADDITION -record already exists
-INVALID CHANGE -record does not exist
-INVALID DELETION -record odesn't not exist
Thanks in Advance!!!
P.S. I did this project in another way, which I use a list box to process product codes submitted by the user...but it is totally wrong!1so I need ur guys help!!!!I don't know what to do!
lawlaw81 07-21-2003, 10:56 AM Thanks Passel!!
I think my data is separated by comma, cos it looks like this in the sequential disk file:
"L666", "Surge Protector", "Pc King", 3.30, 160, "N"
"M013", "MS Mouse", "Memory-Rex", 23.22, 28, "N"
and so on......
|