Re: Passing Function Values
I think I solved it, at least its working for what I need. If there is abetter/more correct way of doing this please let me know:
Code:
Public Type FontInfo
Fcolor As Integer
Fsize As Integer
Fname As String
End Type
Public Function FontInfo() As FontInfo
FontInfo.Fcolor = EmailForm.TextBox3.ForeColor
FontInfo.Fsize = EmailForm.TextBox3.Font.size
FontInfo.Fname = EmailForm.TextBox3.Font.Name
End Function
Re: Passing Function Values
using a type instead of 3 variables is a very good idea, you could, if needed, also use variables to hold different instances of your type
Re: Passing Function Values
Quote:
Originally Posted by
westconn1
using a type instead of 3 variables is a very good idea, you could, if needed, also use variables to hold different instances of your type
Thank you it seemed like the best approach but just for my own knowledge can you give me an example using variables?
Re: Passing Function Values
Quote:
Public Type FontInfo
Fcolor As Integer
Fsize As Integer
Fname As String
End Type
Public Function FontInfo() As FontInfo
FontInfo.Fcolor = EmailForm.TextBox3.ForeColor
FontInfo.Fsize = EmailForm.TextBox3.Font.size
FontInfo.Fname = EmailForm.TextBox3.Font.Name
End Function
note there are some issues with your code as posted that i failed to notice before
you should not have a procedure name the same as the name for your type, fcolor may overflow as integer, change to long, the values for fontinfo are not retained, but returned each time fontinfo is referenced, thiat is it always gets the current state
assuming you want to save the vales for future reference, try like
vb Code:
Public Type FontInfo
Fcolor As Long
Fsize As Integer
Fname As String
End Type
Public tbfi As FontInfo ' public is only required if you need to be able to access this variable from any other form or module, else use Dim
Public Sub getFontInfo()
tbfi.Fcolor = UserForm1.TextBox1.ForeColor
tbfi.Fsize = UserForm1.TextBox1.Font.Size
tbfi.Fname = UserForm1.TextBox1.Font.Name
End Sub
Sub anyprocedure()
getFontInfo ' use this to get the font state at any time, the values are retained
End Sub
Sub any()
MsgBox tbfi.Fname ' use like this to return the retained values at any time from any procedure
' or return the textbox to original state
End Sub
you can define several variables to retain the font values from different points to return later, just declare them all as type fontinfo as above