473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how do I use a variable to change a color

I am creating a program with a changeable background color for a lot of buttons and I need to be able to save all of those colors and then open them back up when the program is opened again.

If I recall a textfile with the value "Blue" for color, then how can I use that?

I was thinking something like

------------------
abcde = "Blue"

Button1.Backcolor = Color.abcde
-------------------

But I don't know how to make that work
Sep 6 '07 #1
7 6361
kadghar
1,295 Expert 1GB
I am creating a program with a changeable background color for a lot of buttons and I need to be able to save all of those colors and then open them back up when the program is opened again.

If I recall a textfile with the value "Blue" for color, then how can I use that?

I was thinking something like

------------------
abcde = "Blue"

Button1.Backcolor = Color.abcde
-------------------

But I don't know how to make that work
the idea is good, but instead of saving thw word blue, why dont you save the RGB combination in a Color Array

dim CArr() as byte
'say you have 5 differente colours
redim carr(1 to 5, 1 to 3)
'you have Blue, Yellow, Black, White and Red
'For Blue
carr(1,1)=0
carr(1,2)=0
carr(1,3)=255

'and then when you load them just:
button1.backcolor=rgb(carr(1,1),carr(1,2),carr(1,3 ))
'and so on.

To know the combination of any color, just go to paint, there you have the palette

you an also use vb constants, i dont remember them but seems that
button1.backcolor=vbblue will do

HTH
Sep 6 '07 #2
When persisting such settings, I use the registry functions:
- SaveSetting
- GetSetting
Just a thought.
Sep 6 '07 #3
Robbie
180 100+
I am creating a program with a changeable background color for a lot of buttons and I need to be able to save all of those colors and then open them back up when the program is opened again.

If I recall a textfile with the value "Blue" for color, then how can I use that?

I was thinking something like

------------------
abcde = "Blue"

Button1.Backcolor = Color.abcde
-------------------

But I don't know how to make that work
You seem to be asking how to actually refer to colours, since you know that "Blue" doesn't work.

You seem to already be able to save and load the word.

But you shouldn't save "Blue".
Save the BackColor property. For example, for Blue, you can get the number which represents that colour using RGB(0,0,255)
.
(RGB means Red, Green, Blue - each ranges from 0 to 255. So that example above represents no red, no green, maximum blue, = a pure blue colour).

RGB there will give you back 16711680. This is just a number that represents that colour. So save that number to the file, then when you reload it, set the appropriate object's BackColor value to cStr(ThatNumber).

I may have got the wrong end of the stick... if you actually want to know how to save and load from the text file, I can tell you that too, just ask. ;)

EDIT: In other words, colour values are simply numbers of Long type.
If you want to know more on how to decode these long numbers back to the actual Red, Green and Blue values, I explained roughly how to do so here:
http://www.thescripts.com/forum/thread701351.html
Sep 7 '07 #4
Killer42
8,435 Expert 8TB
Keep in mind, there's no reason why you can't use a more easily human-readable value such as "Blue". But you will need to write some code to convert between that and the "Real" colour value.
Sep 8 '07 #5
Robbie
180 100+
Keep in mind, there's no reason why you can't use a more easily human-readable value such as "Blue". But you will need to write some code to convert between that and the "Real" colour value.

Oh yes, that's right, Sorry Philly...

You could always save "Blue", then when reading it, use a Select-Case statement or something to convert it back to RGB(255,0,0).

But, I was trying to give a more universal way of doing things, so you could give your users a whole gradient colour pallette, and they could pick any colour, without you having to hard-code the alternative 'words' for 16,581,375 different colour values. ^^;;
Sep 8 '07 #6
Killer42
8,435 Expert 8TB
Oh yes, that's right, Sorry Philly...
I don't think there's any need to apologise. Storing the actual value is almost certainly the preferred method. I just wanted to point out that you always have the option of doing these things pretty much any way you want, it may just require more work.

I'm actually in favour of making data files human-readable wherever possible, just so you can tell what they mean when you see them in a couple of years, after forgetting the program.
Sep 9 '07 #7
Ali Rizwan
925 512MB
OK
If you want to apply colors fetching color names from text file. If yes then following file will help u a lot.
Attached Files
File Type: zip Colors.zip (1.6 KB, 279 views)
Sep 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Jack | last post by:
How would I add a variable that I will assign to a list of $_POST variables that I extract from a form? My form passes a value for $q. That works fine. What I want to do is run an if/else on it...
1
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System...
6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
3
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the...
3
by: Byron | last post by:
Hi, Javascript confuses me, so I usually limit myself to Dreamweaver's built-in scripts for stuff like imageswaps. But this time I'm trying to write something very simple myself. I do most of my...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
1
by: Varadha | last post by:
Hi, I am declaring a variable static char Version_No = '1' in header file header.h In a application "app.exe", i am changing the value of the variable in to '2' In the same application i am...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
9
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.