For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > March 2006 > Showing array contents on a form









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Showing array contents on a form
BruceS

2006-03-29, 6:56 pm

Hi!

Worked with Office VBA a while, but attempting first shot at straight VB.
Using VB 6.0 SP 6 in Visual Studio and have a couple of things I need to
learn how to do.

As notes, this project has no data source. Data is loaded from text files,
massaged somewhat, then placed into various arrays for processing. Output is
sent back to text files. Users aren't guaranteed to have even Excel, much
less Access or any other particular data storage/retreival program. Project
must be distributed as stand-alone .exe, so we can't package as Access .mde
with runtime or in any other form that has to be "installed".

Have two questions:

1) I need to display the contents of an array on a form so that user can
make changes. Want to show them something like a data grid. Looking for
some example code or forms that I can adapt to display/edit the array.

2) Strictly for my own amusement, how does one display an animated .gif on a
VB form? I can find info in help on .avi, but not on .gif.

Any advice/assistance greatly appreciated.

Thanks,
Bruce
Ivar

2006-03-29, 6:56 pm


"BruceS" <BruceS@discussions.microsoft.com> wrote in message
news:D4928645-23A7-41C4-9235-5932E4B15660@microsoft.com...
>Project must be distributed as stand-alone .exe,
>so we can't package as Access .mde with runtime
>or in any other form that has to be "installed".


Does this mean that you can only distributed an exe file, that is made using
VB without any external references or components? You got to have the VB6
runtime files for any VB6 exe to work. I think I'm right in saying that a VB
standard exe compiled without any external references or components will
work OK on any windows PC with 98ME and later, and 95 & 98 if any other VB
prog is installed.
If that's the case then what you are asking is very possible, but a lot of
work.



BruceS

2006-03-29, 9:55 pm

Ivar,

Again, I'm new to all of this...I was assuming that the libraries in my
references would be included with the build. Program is defined for use with
NT/2K/XP. Planned to test with 98, but it's not mandatory. (Assuming that
we can find a machine that old!)

The array data grid is not absolutely, positively mandatory, but would be a
real convenience to the user and allow us to emulate their current
procedures. It would be worth a little extra effort to include it. Any idea
on accomplishing the feat?

Thanks,
Bruce

"Ivar" wrote:

>
> "BruceS" <BruceS@discussions.microsoft.com> wrote in message
> news:D4928645-23A7-41C4-9235-5932E4B15660@microsoft.com...
>
> Does this mean that you can only distributed an exe file, that is made using
> VB without any external references or components? You got to have the VB6
> runtime files for any VB6 exe to work. I think I'm right in saying that a VB
> standard exe compiled without any external references or components will
> work OK on any windows PC with 98ME and later, and 95 & 98 if any other VB
> prog is installed.
> If that's the case then what you are asking is very possible, but a lot of
> work.
>
>
>
>

Larry Serflaten

2006-03-29, 9:55 pm


"BruceS" <BruceS@discussions.microsoft.com> wrote

> 1) I need to display the contents of an array on a form so that user can
> make changes. Want to show them something like a data grid. Looking for
> some example code or forms that I can adapt to display/edit the array.


See if the code below will give you a few ideas.

>
> 2) Strictly for my own amusement, how does one display an animated .gif on a
> VB form? I can find info in help on .avi, but not on .gif.


You might put a webcontrol on the form, and show a page that includes your GIF file,
or you might break out the individual frames and animate the images yourself. VB
doesn't support GIF animation by itself...

For #1, you can use textboxes on a form to simulate your grid and then use a
scrollbar (or buttons, as shown) to scroll through the data. For an example, add
a Command button and a Textbox to a new form and set their Index properties to
0, then paste in the code below....

HTH
LFS

Option Explicit
Private TextData(0 To 2, 1 To 25) As String
Private Page As Long
Private Updating As Boolean

Const MarginX = 990
Const MarginY = 300
Const ColumnOffset = 100
Const PageOffset = 5

Private Sub ShowPage()
Dim x&, y&, tb As Long
' Display text
Updating = True
For y = 1 To PageOffset
For x = 0 To 2
tb = y + x * ColumnOffset
Text1(tb) = TextData(x, y + Page)
Next x
Next y
Updating = False
Command1(1).Enabled = (Page > 0)
Command1(2).Enabled = (Page > 0)
Command1(3).Enabled = (Page < 20)
Command1(4).Enabled = (Page < 20)
End Sub

Private Sub Text1_Change(Index As Integer)
Dim x&, y As Long
' Update data array
If Updating Then Exit Sub
x = Index \ ColumnOffset
y = Index - (x * ColumnOffset) + Page
TextData(x, y) = Text1(Index).Text
End Sub


Private Sub Command1_Click(Index As Integer)
' Page selection
Select Case Index
Case 1
Page = Page - PageOffset
Case 2
Page = Page - 1
Case 3
Page = Page + 1
Case 4
Page = Page + PageOffset
End Select

If Page < 0 Then Page = 0
If Page > 20 Then Page = 20
ShowPage
End Sub

Private Sub Form_Load()
Dim x&, y&, z As Long
' Form init
Move Left, Top, 3075, 2790
With Command1(0)
.Move 0, 0, 600, 360
.Font.Name = "arial"
.Font.Size = 14
.Font.Bold = True
.Caption = ""
.Visible = False
End With

With Text1(0)
Updating = True
.Text = ""
Updating = False
.Move 0, 0, 900, 240
.Visible = False
End With

' Create more textboxes
For y = 1 To PageOffset
For x = 0 To 2
z = y + x * ColumnOffset
Load Text1(z)
With Text1(z)
.Move x * MarginX + 30, y * MarginY
.Visible = True
End With
Next x
Next y

' Create more command buttons
For x = 1 To 4
Load Command1(x)
With Command1(x)
.Move x * 660 - 480, 2000
.Caption = Array("", "<<", "<", ">", ">>")(x)
.Visible = True
End With
Next x

TextData(0, 1) = "Enter"
TextData(1, 1) = "Data"
TextData(2, 1) = "Anywhere"
ShowPage
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim ctl
' Clean up
For Each ctl In Text1
If ctl.Index Then Unload ctl
Next

For Each ctl In Command1
If ctl.Index Then Unload ctl
Next
End Sub







BruceS

2006-03-30, 3:55 am

Larry,

Wow! This is a lot more than I expected anyone to send. Thank you!

Will play with it tomorrow and see if I can get it to fly.

Bruce

"Larry Serflaten" wrote:

>
> "BruceS" <BruceS@discussions.microsoft.com> wrote
>
>
> See if the code below will give you a few ideas.
>
>
> You might put a webcontrol on the form, and show a page that includes your GIF file,
> or you might break out the individual frames and animate the images yourself. VB
> doesn't support GIF animation by itself...
>
> For #1, you can use textboxes on a form to simulate your grid and then use a
> scrollbar (or buttons, as shown) to scroll through the data. For an example, add
> a Command button and a Textbox to a new form and set their Index properties to
> 0, then paste in the code below....
>
> HTH
> LFS
>
> Option Explicit
> Private TextData(0 To 2, 1 To 25) As String
> Private Page As Long
> Private Updating As Boolean
>
> Const MarginX = 990
> Const MarginY = 300
> Const ColumnOffset = 100
> Const PageOffset = 5
>
> Private Sub ShowPage()
> Dim x&, y&, tb As Long
> ' Display text
> Updating = True
> For y = 1 To PageOffset
> For x = 0 To 2
> tb = y + x * ColumnOffset
> Text1(tb) = TextData(x, y + Page)
> Next x
> Next y
> Updating = False
> Command1(1).Enabled = (Page > 0)
> Command1(2).Enabled = (Page > 0)
> Command1(3).Enabled = (Page < 20)
> Command1(4).Enabled = (Page < 20)
> End Sub
>
> Private Sub Text1_Change(Index As Integer)
> Dim x&, y As Long
> ' Update data array
> If Updating Then Exit Sub
> x = Index \ ColumnOffset
> y = Index - (x * ColumnOffset) + Page
> TextData(x, y) = Text1(Index).Text
> End Sub
>
>
> Private Sub Command1_Click(Index As Integer)
> ' Page selection
> Select Case Index
> Case 1
> Page = Page - PageOffset
> Case 2
> Page = Page - 1
> Case 3
> Page = Page + 1
> Case 4
> Page = Page + PageOffset
> End Select
>
> If Page < 0 Then Page = 0
> If Page > 20 Then Page = 20
> ShowPage
> End Sub
>
> Private Sub Form_Load()
> Dim x&, y&, z As Long
> ' Form init
> Move Left, Top, 3075, 2790
> With Command1(0)
> .Move 0, 0, 600, 360
> .Font.Name = "arial"
> .Font.Size = 14
> .Font.Bold = True
> .Caption = ""
> .Visible = False
> End With
>
> With Text1(0)
> Updating = True
> .Text = ""
> Updating = False
> .Move 0, 0, 900, 240
> .Visible = False
> End With
>
> ' Create more textboxes
> For y = 1 To PageOffset
> For x = 0 To 2
> z = y + x * ColumnOffset
> Load Text1(z)
> With Text1(z)
> .Move x * MarginX + 30, y * MarginY
> .Visible = True
> End With
> Next x
> Next y
>
> ' Create more command buttons
> For x = 1 To 4
> Load Command1(x)
> With Command1(x)
> .Move x * 660 - 480, 2000
> .Caption = Array("", "<<", "<", ">", ">>")(x)
> .Visible = True
> End With
> Next x
>
> TextData(0, 1) = "Enter"
> TextData(1, 1) = "Data"
> TextData(2, 1) = "Anywhere"
> ShowPage
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> Dim ctl
> ' Clean up
> For Each ctl In Text1
> If ctl.Index Then Unload ctl
> Next
>
> For Each ctl In Command1
> If ctl.Index Then Unload ctl
> Next
> End Sub
>
>
>
>
>
>
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com