Help! Array element to textbox

Displaying Array element in a textbox problem

Page 1 of 1

3 Replies - 8671 Views - Last Post: 02 May 2008 - 07:27 AM Rate Topic: -----

#1 Spamicide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-May 08

Help! Array element to textbox

Posted 01 May 2008 - 12:15 PM

Why does this not work? It is suppose to display the values of the array in the text box but some of them do not show up.





Private Sub FirstLine()

Dim iFirstRowOrdered(9) As String
Dim V As Integer

Dim iRow1(9) As String


iFirstRowOrdered(0) = "1"
iFirstRowOrdered(1) = "2"
iFirstRowOrdered(2) = "3"
iFirstRowOrdered(3) = "4"
iFirstRowOrdered(4) = "5"
iFirstRowOrdered(5) = "6"
iFirstRowOrdered(6) = "7"
iFirstRowOrdered(7) = "8"
iFirstRowOrdered(8) = "9"

Dim RowCell As Integer
Dim A As Integer



RowCell = 0
A = 9
Randomize
Do
  x = Int(Rnd(1) * A)
  iRow1(RowCell) = iFirstRowOrdered(x)
  Text6 = Text6 & iRow1(RowCell)
  iFirstRowOrdered(x) = iFirstRowOrdered(A)
  A = A - 1
  RowCell = RowCell + 1
Loop While A > 0

	  txtRow1Cell1.Text = iRow1(0)
	  txtRow1Cell2.Text = iRow1(1)
	  txtRow1Cell3.Text = iRow1(2)
	  txtRow1Cell4.Text = iRow1(3)
	  txtRow1Cell5.Text = iRow1(4)
	  txtRow1Cell6.Text = iRow1(5)
	  txtRow1Cell7.Text = iRow1(6)
	  txtRow1Cell8.Text = iRow1(7)
	  txtRow1Cell9.Text = iRow1(8)

End Sub









Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Help! Array element to textbox

#2 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Help! Array element to textbox

Posted 01 May 2008 - 01:39 PM

I'm not sure why it does not work but try this: create to list boxes a command button and a textbox and use this code
Private Sub Form_Load()

  'assure random numbers don't
  'repeat each run
   Randomize
	  
End Sub
		 
		 
Private Sub Command1_Click()

  'Set the number of elements needed. This demo
  'uses 1 to 52 to simulate a deck of cards.
   Dim cnt As Long
   Dim myArray(1 To 52) As Long
   
  'lists are for info only
   List1.Clear
   List2.Clear
   
  'fill the array with consecutive numbers from 1 to 52
   For cnt = 1 To UBound(myArray)
	  myArray(cnt) = cnt

	 'debug/info only - not needed for routine
	  List1.AddItem cnt & vbTab & myArray(cnt)
   Next
   
  'randomize (suffle) the array values
   RandomizeArray myArray
   
  'debug/info only - not needed for routine
   For cnt = 1 To UBound(myArray)
	  List2.AddItem cnt & vbTab & myArray(cnt)
   Next
   'this is what i need
   Text1.Text = Val(myArray(1))
   End Sub


Private Sub RandomizeArray(ArrayIn As Variant)
   
   Dim cnt As Long
   Dim RandomIndex As Long
   Dim tmp As Variant
   
  'only if an array was passed
   If VarType(ArrayIn) >= vbArray Then
		
	 'loop through the array elements in reverse
	  For cnt = UBound(ArrayIn) To LBound(ArrayIn) Step -1
	  
		'select a random array index
		 RandomIndex = Int((cnt - LBound(ArrayIn) + 1) * _
					   Rnd + LBound(ArrayIn))
									
		'cnt represents one array member
		'index, and RandomIndex represents
		'another, so swap the data held in
		'myarray(cnt) with that in myarray(RandomIndex)
		 tmp = ArrayIn(RandomIndex)
		 ArrayIn(RandomIndex) = ArrayIn(cnt)
		 ArrayIn(cnt) = tmp
		 
	  Next
	  
   Else
   
	 'The passed argument was not an
	 'array; error handler goes here
	  
   End If
  
End Sub


Private Sub List1_Scroll()

  'if List2 is scrolled, keep List1 in sync
   List2.TopIndex = List1.TopIndex
   
End Sub


Private Sub List2_Scroll()

  'if List1 is scrolled, keep List2 in sync
   List1.TopIndex = List2.TopIndex

End Sub



If this is help full message me back
Was This Post Helpful? 0
  • +
  • -

#3 Spamicide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-May 08

Re: Help! Array element to textbox

Posted 02 May 2008 - 07:25 AM

Thankyou very much! The code u provided was very helpful
seems if i use array(1 to 9) instead of array(9) and Val(array(1)) it works fine.
Was This Post Helpful? 0
  • +
  • -

#4 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Help! Array element to textbox

Posted 02 May 2008 - 07:27 AM

it is easy to change that was from one of my programs that i have made and it is brilliant
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1