Strict Color Data Types  
Author Message
Slyke





PostPosted: Visual Basic Language, Strict Color Data Types Top

Hey, i know what the problem is here, but i don't know how to fix it!

Texttxt.ForeColor = GetSetting("My_Program", "Program_Options", "Fore_Col-Col", Color.Black)

It says that it won't work because Color.Black can't be a string.

Now i know there's a simple way around this problem...
But i'd also like to know how to prevent this type mismatch (i believe that's what it's called) from happening again with ALL data types. Can any one give me some magical web page with all the answers (and solve this) too please


Visual Basic10  
 
 
Slyke





PostPosted: Visual Basic Language, Strict Color Data Types Top

Come on... it's not that difficult is it... I did look for thje answer myself.

 
 
DMan1





PostPosted: Visual Basic Language, Strict Color Data Types Top

No to sure what your asking but maybe this will help

all Objects have a ToString method

The Convert Class has methods for converting from one type to the next

DIrectCast will allow you to cast from one type to the next...

GetType will return the type of an object

TypeOf will test the type of an object

Hope that Helps...



 
 
Slyke





PostPosted: Visual Basic Language, Strict Color Data Types Top

I'm trying to save the foreground color of a textbox usin that SaveSetting & getsetting commands.

 
 
spotty





PostPosted: Visual Basic Language, Strict Color Data Types Top

Change the setting type to system.drawing.color instead of string.


 
 
DMan1





PostPosted: Visual Basic Language, Strict Color Data Types Top

Dim MyForeGroundColor as Color = TextBox1.ForeColor

 
 
Slyke





PostPosted: Visual Basic Language, Strict Color Data Types Top

That's not the actual problem, it's saying that Color.Black can't be a string.

Texttxt.ForeColor = GetSetting("My_Program", "Program_Options", "Fore_Col-Col", Color.Black)

That's where the error is, is there something that i put around that with brackets
That's the default value when the GetSetting command is called.

I tried

Dim Temp_Color As Color = Color.Black

Texttxt.ForeColor = GetSetting("My_Program", "Program_Options", "Fore_Col-Col", Temp_Color)

But the same error occured.

 
 
spotty





PostPosted: Visual Basic Language, Strict Color Data Types Top

If your using VB express 2005 then this is extremely simple to save settings to the application.configuration file and not to the registry

If you want to do setting is VB Express/2005 then simply add the settings in My Project -> set the type in my case system.drawing.color

and use

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'//Change and Save Setting
My.Settings.Forecolor = Color.Black
My.Settings.Save()

'//I have a setting called forecolor and its set
Me.Label1.BackColor = My.Settings.Forecolor

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'//Change and Save Setting
My.Settings.Forecolor = Color.Aquamarine
My.Settings.Save()

'//I have a setting called forecolor and its set
Me.Label1.BackColor = My.Settings.Forecolor
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.ForeColor = My.Settings.Forecolor '//Load Setting
End Sub
End Class


Its extremely simple and the setting is strongly typed to system.drawing.color.


 
 
Slyke





PostPosted: Visual Basic Language, Strict Color Data Types Top

 

If you want to do setting is VB Express/2005 then simply add the settings in My Project -> set the type in my case system.drawing.color



I'm still learning VB 2005 (as you can probebly tell, lol). I don't understand this bit.

I checked it out, however and i think that i got it.

This is the screen where you name the settings Instead of calling it "Fore_Color" in the code, we name it there. Im reading the help i just found about it now thanks!

We have to My.Settings.Save everytime we update the values Because it won't save after the program has ended if we don't

 
 
spotty





PostPosted: Visual Basic Language, Strict Color Data Types Top

The My.Settings.Save actually persist the settings to the configuration file otherwise you are only chnaging the in-memory copy and if you restart the application it will use the last persisted settings not the last in-memory ones.