|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
Array Issue like Array('one'), Array('two'), etc...
I know that in PHP, the array can be like this...
--snip-- $Array['red'] = "FF0000"; $Array['blue'] = "00FF00"; $Array['black'] = "000000"; echo $Array['black']; --snip-- But in visual basic, how do I make this work... --snip-- dim strArray as string strArray(red) = "FF0000" strArray(blue) = "00FF00" strArray(black) = "000000" frmForm.txtText.text = strArray(black) --snip-- Am I doing something wrong? Does it work or what? I only see from the internet search that only integer can be use like 0, 1, 2, 3, etc.. Thanks, Scott F. |
|
#2
|
||||
|
||||
|
well, one possible solution would be declare a public constant to represent your colors....
I used the RGB Function instead of hex, and wrote this small example Code:
Const Black As Integer = 0
Const Red As Integer = 1
Private Sub Form_Load()
Dim aryColors(2) As Integer
Dim strInput As String
aryColors(Black) = RGB(0, 0, 0)
aryColors(Red) = RGB(255, 0, 0)
strInput = CStr(InputBox("What color would you like the form to be?", "Color Preference"))
Select Case strInput
Case "Black"
Form1.BackColor = aryColors(Black)
Case "Red"
Form1.BackColor = aryColors(Red)
Case Else
MsgBox "The Color you Entered is not valid. Will Default to Black", vbOKOnly, "Invalid"
Form1.BackColor = aryColors(Black)
End Select
End Sub
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
||||
|
||||
|
I just thought, I'm fairly sure that VB does not like Hex unless it is enclosed in "#"s. so, if you're going to do "000000", then, it should be "#000000#", but I don't know if it will like the hex value as a string anyway...I'll try it though!
|
|
#4
|
||||
|
||||
|
Thanks for the clarification. Gee, look like Visual Basic doesn't have that flexibility with the array. Seem it work only with integer value in the array. Dynamic array is tricker here in visual basic. Oh well, I guess we all have to live with it.
Thanks... |
|
#5
|
|||
|
|||
|
I provider a function which can Chang long color value to RGB color value function!
Public Function ColorCodeToRGB(lColorCode As Long, iRed As Integer, iGreen As Integer, iBlue As Integer) As Boolean ' 1996/01/16 Return the individual colors for lColorCode. ' 1996/07/15 Use Tip 171: Determining RGB Color Values, MSDN July 1996. ' Enter with: ' lColorCode contains the color to be converted ' ' Return: ' iRed contains the red component ' iGreen the green component ' iBlue the blue component ' Dim lColor As Long lColor = lColorCode 'work long iRed = lColor Mod &H100 'get red component lColor = lColor \ &H100 'divide iGreen = lColor Mod &H100 'get green component lColor = lColor \ &H100 'divide iBlue = lColor Mod &H100 'get blue component ColorCodeToRGB = True End Function See more information: http://www.buygold.net/v02n04/v02n04.html |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Array Issue like Array('one'), Array('two'), etc... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|