Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




ENUM String


Trying something new here and having a bit of a problem.I declare an Enumerator
Code:
Private Enum TableNames TableName_DOC = "TB_DOC" TableName_CCA = "TB_CCA" TableName_CCD = "TB_CCD" TableName_PRO = "TB_PRO" TableName_PRD = "TB_PRD"End Enum
But when I call the enumerator as an input to a function I get a type mismatch error.
Code:
Public Function GetNextKey(strTableNames As TableNames) As String
Is it because Enums can not contain strings or something else entirely? ThanksBrian




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Enum In Enum In Enum In Type In Enum?.. Whoah
Hey folks... I don't know the possiblilty of this, but what the hell..

Is it possible to have an enum under another enum?.. or under another UDT?..

so I could for example go..

SystemDefaults.ServerDefaults.serv_HTTP

where SystemDefaults is either a toplevel enum/UDT for other default property lists..

.ServerDefaults is another enum housing;

.serv_HTTP = 80
.serv_FTP = 21
.
.
.
etc...

thanks in advance.. any advice much appreciated

String <----> Enum
How can I convert a string to its corresponding enum value in visual basic 6? I have a textbox and I want the user to be able to enter the info into the text box and then if it is "fish" it will go to animals.fish. How do I do this? I was thinking of looping through the enum values, but how do you loop? I was thinking of casting the string, but how does one cast in VB6? There is no posibilty of using a big if statement or select statement becausae there are over 150 values in the enum, so what do I do? Preferably, I would use a combobox with the choises of the enum values. But how would I do this?

String Enum
Well i ran into thise problem today

I wanted to create a public enum like thise.


Code:
Public Enum GoogleLGUse
arabisk = ar
bulgarsk = bg
danish = da
english = en
finsk = fi
french = fr
greek = el
hindi = hi
dutch = nl
italian = it
japansk = ja
kinisisk = zh - CN
koreansk = ko
norwegian = no
polish = pl
portuguese = pt
romanian = ro
russian = ru
Spanish = es
swedish = sv
czech = cs
german = de
detect = auto
End Enum


And have it pass tru a function, like thise

Code:
public Function GetTranslation(textTrans as string, fromLang as GoogleLGUse, toLang as GoogleLGUse) as string


My problem is that thise dosent work because enum dosent work whit string only Longs

So i seach google and some write the use of const to use in enum, but have can i get that to work in my function when i just want specifik.

any suggestion?

I was using just string, instead. But i wanted to improve it

Enum For String Constants?
I want to declare few string constants. Can Enum be used to declare these? I understand enum can be used for declaring numberic (long) constants. In such case, how can string constants be declared in enum?

String Version Of Enum
I know this sounds impossible, but i thought i would ask anyway.

anyway you pass a function an enum type thing, and it spits out that enum name back as a string!?

How Do You Convert A String To Enum Datatype?
Hi All

I have probably looked at all 8 billion pages on the web and still can't find an example I can understand - can anybody help.

I am looking for a function or a sub that will convert a string to the relavent enum datatype. Below is the code I currently have (stripped down to the minimum).

modTCPData.bas =============================================


VB Code:
Option Explicit Public Enum CommType    COMMSEnd Enum Dim vCommRec As Variant Public Sub ProcessGameData(DataRec As String)    frmMain.txtDataRec.Text = DataRec & vbCrLf & frmMain.txtDataRec.Text        vCommRec = Split(DataRec, "|")        Select Case vCommRec(0)        Case COMMS            frmMain.txtComms.Text = vCommRec(1) & frmMain.txtComms.Text    End SelectEnd Sub

==========================================================

Example Data
-----------------------------------------------------
DataRec = "COMMS|The some text."

vCommRec(0) = "COMMS" (after Split)
vCommRec(1) = "The some text." (after Split)
-----------------------------------------------------

Cheers, I hope somebody can help.

Grisham

Advice On Enumerations In Classes And Enum String Value
I was looking for some general advice about using enumerations in classes.

Say i have a class, clsUser, with the following enum:


Code:
public enum enuGender
Male = 0
Female = 1
end enum

To use these, i declare a private integer to hold the selected enum index. Is this right?


Code:
Private intSelectedGender as integer

Public property Get Gender() as enuGender
Gender = intSelectedGender
end property

Public Property Let Gender(byval sex as enuGender)
intSelectedGender = sex
end property

At this point i want to ask my second question - is it acceptable to store enum integer values in a database? For instance, in my db table of Users, should i store 0 / 1 under the gender field, or translate this integer value into a string representation of "Male" / "Female" ?

This ties in with my third question - should i get string values for the selected enum value? At the moment, i have not, and wherever i access my User class, the calling code is littered with:


Code:
select case objUser.Gender
case 0
text1.text = "Male"
case 1
text1.text = "Female"
end select

which seems quite redundant and would be a pain to change in the future. I thought of a public class property that would get the string value of the selected enum index, something like:


Code:
Public Property Get GenderString() as string
select case intSelectedGender
case 0:
GenderString = "Male"
case 1:
GenderString = "Female"
end select
end propety

which i could access like:

Code:
text1.text = objUser.GenderString

But then this bloats the class interface. Whats the opinion of this approach?

(by the way i'm using vb6)

Enum / End Enum
I have seen many source codes for games where they have something called Enum and then a list of things, and then End Enum. What does this do?

--Defiance



"Soon I will answer your questions, now you will answer mine..."

Enum In VBA
i have this code in VB:
Public Enum Commodity
Gas = 0
Power = 1
Coal = 2
End Enum

I want to convert this in VBA,but VBA doesnt accept it as i have office '97,so how do i do it..VBA doesnt seem to recoginize the Enum key word

Thanks
Sree

Enum Pos
My boss has given me the dubious task of creating a form with textboxes that must have a certain enum position. Is there any way to determine what a control's enumeration position will be at design time?

Enum Name
Hi there.

Does anyone know how to get an enum name (as string)?

ex:
Enum MyEnum
One = 1
Two = 2
end Enum

Dim X as MyEnum
Dim MyEnumString as String

x = One
MyEnumString = x 'this gives-me 1 but I want "One" as string


Thanks

Enum
In my code I have declared an enum type

Code:
Public Enum Wdays
Monday = 0
Tuesday = 1
Wednesday = 2
Thursday = 3
Friday = 4
End Enum

I have a database that has the fields Monday, Tuesday etc. If i declare

Code:
dim MyDay As Wdays
How can I access these fields using the actual variable? eg.

Code:
rsMyRS!MyDay ' Every time MyDay is changed it will
'Access the corresponding record ie. MyDay=Monday
' then it will access rsMyRS!Monday and so on.
Also how do I increment MyDay ie from monday to tuesday and so on.
Any help would be greatly appreciated

Enum??
can anybody tell me what
enum / end enum is? can you expain it??

Using Enum??
how do i use enum??
I meant add or extract infomation
I think i know how to delare it but i am not sure about adding or extracting....coz i am more familar with struct in C


Code:
Public Enum User
Name As String
Pass As String
StartDate As Date
EngScore As Integer
MathScore As Integer

End Enum

Enum
I've seen "enum" in a few pieces of code that I've looked at in the past little while and I was curious what it was used for. Could any1 tell me or perhaps give a simple example of where it could be used? Thx

Enum And End Enum
Hey, I had this same question posted in the game section but no one answered it. Anyways, what is the Enum and End Enum code? I have seen it associated with many games, but what does it do. Here is an example of some of the uses I've seen it been put to:

Enum
Fist
Knife
Sword
Axe
End Enum

Can anyone please explain it?

--Defiance



"Soon I will answer your questions, now you will answer mine..."

Enum In Vb
like in c++:

Code:
enum {
HELLO,
SLAP,
BLAH
};

this possible in vb?

edit: stupid question, ::

VB Code:
Public Enum Blah' codeEnd Enum

Enum Help
Lo all, Im using alot of enum's in my project and am having to use numbers instead of the enumeration because of 'Ambigous Name' errors. I've declared my emuns like this


VB Code:
Public Enum EnumCharacterType    Player = 0    Vendor    PlayerVendor    Monster    MountEnd Enum


Ive tried declaring as private but since they are used in a UDT a module other than the one that its declared in cant see it. Any ideas on how to get round it other than calling everything different names (I have alot of None enums hehe). I know that they are like constants so if there isnt a work arround how could I 'resuse' another enum so to speak. i.e


VB Code:
Public Enum PlayerType     Player = 0     Vendor     PlayerVendor     Monsterend enum Public Enum AccountLevel    Player = 0    GameMaster    Adminend enum Type TPlayer   'blah   'blah   AccLevel as AccountLevel   Ptype as PlayerTypeend type Public Player as TPlayer 'Now this would cause an error If Player.Ptype = Player Then     'bahend if


As both are called player it would cause this error again is there a way to reuse the Player from one of them??

Enum
can anyone explain to me what Public Enum does?
i saw it in a program but i have no idea it does.
thanks

DAO And Enum`s
I have a problem using enums in a DAO query
seems that dec.m_MediaType = 1 when i am looking to match a STRING in a table.

Is there a way around this? or am i stuck putting index numbers in my access table. ?





VB Code:
rstVelocity.Index = "PrimaryKey"    rstVelocity.Seek "=", dec.m_MediaType ' NEED STRING NOTNUMBER        mDucting.Description.m_roomVelocity = rstVelocity(1) 'just in case we need it        mDucting.Description.m_cfm = rstVelocity(1) * (dec.m_roomWidth * dec.m_roomHeight)rstVelocity.Close     ' HERES MU ENUM  Public Enum MediaType    AlumOxide    Sand    StarBlast    SteelGritEnd Enum




Thanks Seahag

How Can I Use Enum
Hi all
i want to make function same as MsgBox function that when the user select this function and sened paramter the function show him the options that he can select like when we use msgbox and select the buttons type and it show me more than one options
i tried using Enum but it didn't work with me
can any one help me please
thank you

What Is An Enum?
This may sound very newbie, but what is an enumeration, and what is it's (main) purpose? A simple example would also be nice.

Thanks in advance.

Enum
Help Needed creating ENUM for a .ctl

I have declared on the general section of the UserControl Code window:

Public ENUM bgColor
myWhite = 0
myBlack = 1
myGreen = 2
... etc.
End ENUM

and used the ActiveX control Interface wizard to associate a new Property named bgColor to a textbox.BackColor property but it won't function (Design time), I keep getting the original colors by Microsoft.

Enum
I need to do a project with Enum's --- I need to Get the total enum's in an array and then get the enum's that are = True ..Does anyone know of an article about this stuff???

Enum's In VBA
Hi all,

I have looked through previous threads and can't find an answer to this...

For some reason I can't created Enumeration values in VBA (Excel). It works fine when I declare them in VB, but in the VB editor within Excel it won't allow the creation...

Anybody know why this is?...Is it just a reference which needs adding? How can I create Enum's in VBA?

Thanks to anybody for help
Steve

Enum
Why does this return a type mismatch error?


Code:
Enum frTags
HEADO = "<head>"
BODYO = "<body>"
HEADC = "</head>"
BODYC = "</body>"
End Enum


Can enumerated constants only be numeric?

Enum In VB4?
I'm trying to follow a coding example in VB5 and the words

private enum

end enum

are used in the declarations of a module. Isn there a VB4 equivelency?

Old Man

Enum In VB4?
I'm trying to follow a coding example in VB5 and the words

private enum ...end enum

are used in the declarations section of a module. Is there a VB4 equivelency?


Old Man

What Is An Enum?
what is an enum or an enumeration?

Go From Enum To Strings?
Is it possible to go from an enum type to a string? For example, I have this enum:


Code:
Public Enum GenderType
Male = 0
Female
End Enum
Is it possible for a function to take a variable of GenderType as an argument, and then get to the string "Male" or "Female" based on whether the variable is 0 or 1? I mean besides doing an if/else or select statement. I'd like to use that maneuver on fairly large enums, so i'd rather use something automatic.

thanks,
Rina

Enum To Array
I want to populate the array with values from enum. How can this be done? Number of elements in enum & array are equal.
Also, I how can I set the array size equal to number of elements in enum?

Needed: Help With Enum
whats up peoples?
my final is tomorrow for vb 6.0 and the teach gave us some extra credit which i don't really have to do. but for my better understanding i'm giving it a crack. i wanted to know if someone could explain a lil better what the purpose of an enum is...
(private/public enum name
membername = constantexpression)

also, in the e.c. i'm making a parent/child MDI project where pennies, nickels, dimes, quaters get added into a batchtotal. i wanted to know if i would need to use the enum to get the values of all the child forms into another form displaying the total of all the children's values.

Enum In Paramarray
is it possible to use an enum in a paramarray - i.e. when the user tries to enter values for a paramarray, the list appears with the choices from the enum?
thanks
edit: also, when you set the backcolour of a picture box with a hex colour, then read it back, it is some long number. does anyone know how to convert hex to this?
thanks again

Enum And Type
How are enum or type statments used in visual basic? As in, how are they implemented into a program and what is their purpose? They're confusing me

Enum Quastion
I have declared an Enum:

Code:
Public Enum mon
Jan = 1
Feb = 2
Mar = 3
Apr = 4
May = 5
Jun = 6
Jul = 7
Aug = 8
Sep = 9
Oct = 10
Nov = 11
Dec = 12
End Enum

I want to be able to compare between month that are in strings (f.e m="Feb" , c="Jan")
how can i do it?

Enum Problem Again!
The following loop is meant to go through the days of the working week, monday - friday. If rsMyRS!Monday < rsMyRS2!Monday then found will remain false. If rsMyRS!Tuesday < rsMyRS2!Monday then found will remain false and so on for the other days. My original (ugly) code for this was:

Code:
For i = 1 To 5
Select Case i
Case 1
If rsMyRS!Monday < rsMyRS2!Monday Then Found = False
Case 2
If rsMyRS!Tuesday < rsMyRS2!Tuesday Then Found = False
Case 3
If rsMyRS!Wednesday < rsMyRS2!Wednesday Then Found = False
Case 4
If rsMyRS!Thursday < rsMyRS2!Thursday Then Found = False
Case 5
If rsMyRS!Friday < rsMyRS2!Friday Then Found = False
End Select
Next i
Instead of using that code I declared an enum type as follows

Code:
Public Enum Wdays
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
End Enum
And used the following do loop to replace the for loop.

Code:
Do While MyDay < Wdays.Saturday
If rsMyRS.Fields(MyDay).Value < rsMyRS2.Fields.Item(MyDay).Value Then Found = False
MyDay = (MyDay + 1) Mod 6
Loop
My code doesnt do as it is supposed to. When i debug the do loop it works when MyDay = Monday. But after it is incremented the then statement is always false. Even though i know for a fact the data is true for all cases. What am i doing wrong?

Enum, Class?
I was just wondering if someone could give me a little advice if possible?

-First, I was wondering if there is anyway to create a variable that holds other variables. Something like a class that has no other purpose except holding 2 variables. Can an enum do this? I would use a class, but it seems overkill to create a class just for 2 variables.

-Second, is it possible to create instances of the above variable/class so that I can iterate through the instances based on the order in which they were created?

I'm trying to create a directory structure of a remote computer, starting at a specified domain root directory, and the logic is killing me. This is for an FTP program.

Returning Enum
Module:

Code:
Enum type_Defcon
blue = -1
green = 0
yellow = 1
red = 2
End Enum

Public Defcon As type_Defcon
Form:

Code:
Private Sub Form_Click()
Defcon = Defcon + 1
If Defcon > 2 Then Defcon = -1
Debug.Print Defcon
End Sub
This will print the value of Defcon. But how can I print the names? like blue, green etc.

Why Use Enum Instead Of Constants
What are the differences between constants and Enums?

Why should i use the enum instead just o bunch of constants to determine states.

what are the pro's and con's?

How Do You Use Enum Variables
How do you change the value of Enum variables and return its value?


Code:
Enum Modemstate
Modem_Off = 0
Modem_On = 1
End Enum
When i put this into a module and the next code into a form, it doesn't work:


Code:
Private Sub Command1_Click()
If FishState = Modem_on Then
FishState = Modem_Off
Else
FishState = Modem_on
End If
End Sub

Private Sub Command2_Click()
MsgBox FishState
End Sub
i get a mismatch errors

Type Enum
Hi,
I'd like to write something like that :

Public Enum TwDAT As Short
' DAT_....
Null= 0x0000
Capability= 0x000C
Event= 0x0002
Identity= 0x0003
Parent= 0x0004
PendingXfers= 0x0005
SetupMemXfer= 0x000B
SetupFileXfer= 0x000A

End Enum

Is it possible with vb 6.0 to use Short and this syntax ?
If not, how could I do?
Thanks

Print Enum Value Name
if i have an enum type:


Code:
Public Enum foo
bar=1
baz=2
End Enum
i get "1" if i do "debug.print foo.bar"

how do i do the reverse (get "bar" from "1")?

VB6 [Enum] To Strings
I've looked all over for documentation about how to retrieve the string representation for an enum, but despite compiling, my rendition below raises the 'Object required' error when executed.

Anyone familiar with this who can shed some light on the required arguments?

Code:
Public Function Get_FOEnum(EnumIndex As FinancialObjectType) As String
Dim v

Get_FOEnum = [Enum].getName(v, EnumIndex)

End Function

Enum Constant The Other Way
is there a way to take a enumerated constant and get the string equivalent like 24 = acPolyline???, if a function returns me a number, how do I get it's constant text description??

Enum And Its Point
what does Enum do? here's the code i am working with:


Code:
Public Enum RESOLUTIONS
Res320x240 = 1
Res640x480 = 2
Res800x600 = 3
Res1024x768 = 4
End Enum

Public Function CreateWindow(byref frm as Form, ByVal res as RESOLUTIONS) as Form

'...

Select Case res
Case Res320x240
frm.width = 320 * Screen.TwipsPerPixelX
frm.height = 240 * screen.twipsperpixelY

'and so on for 800x600 and 1024x768

Enum Question ???
hi All,
How can i put space in Enum constants' Name
like we have for BorderStyle for Form..

None = 0
Sizable
Fixed Dialog
Fixed ToolWindow
Fixed Single

It shows me error as soon as i type such constant name

Is it a tric......can we do it???

From Text To Enum (VB6)
Hello all.

Quick question here. (VB6)
I'm programming a game in vb and writing a scripting system for it. I'm reading the scripts from an XML file. Anyway, Some of the script options are Enum, like


Code:
Enum pComparisonType
coEquals = 0
coGreaterThan = 1
coGreaterThanEqualTo = 2
coLessThan = 3
coLessThanEqualTo = 4
End Enum
and a variable within each case is

Code:
CompareType As pComparisonType
Now, I got an xml that I'm reading from. When I read the text from a node, such as 'coEquals' or '0', I can't simply say

Code:
CompareType = node.text
I cant CType it either, because the Enum isn't a recognized type. If I convert the text to an integer, like '0' into 0 then

Code:
CompareType = cint(node.text)
doesnt work either because you cant go from integer to Enum.

Finally, I must do something like

Code:
CompareType = GetpObjectRef(Node.Text)
which calls

Code:
Public Function GetpObjectRef(s As String) As pObjectRef
Select Case s
Case "orRef"
GetpObjectRef = orRef
Case "orAll"
GetpObjectRef = orAll
Case "orNone"
GetpObjectRef = orNone
Case "orAtLeastOne"
GetpObjectRef = orAtLeastOne
Case "orExactlyOne"
GetpObjectRef = orExactlyOne
Case "orEqualToRefNum"
GetpObjectRef = orEqualToRefNum
Case "orGreaterThanRefNum"
GetpObjectRef = orGreaterThanRefNum
Case "orGreaterThanEqualToRefNum"
GetpObjectRef = orGreaterThanEqualToRefNum
Case "orLessThanRefNum"
GetpObjectRef = orLessThanRefNum
Case "orLessThanEqualToRefNum"
GetpObjectRef = orLessThanEqualToRefNum
Case Else
GetpObjectRef = orRef
End Select
End Function
Ofcourse, this works, but its horribly inefficient to write. I'd have to do it for every Enum type variable I have. I could switch to ints instead of Enums, but thats ugly and very unpreferable.

Is there any way to go from text to Enum or from integer to Enum without going through ridiculous amounts of coding? (Visual Basic 6)

Thanks!

Enum Question
You know how when you make an Enum and assign a variable or argument to it, a little popup boxs comes up when you press "=" or "(" so you can easily select a member from that Enum? Is it possible to do that with array subscripts? Like Dim an array, then when you want to refer to it you'd type "ArrayName(" and then the Enum thing would pop up?

Enum Windows
im using the enumwindows function to return a list of the windows running, but it returns all the processes running at the time. How do i filter this using the enumwindows API, and something else, like a function to tell whether the window is actually visible, and check it using that, or a different function to enumwindows, to only return visible windows. All i need to return from it is the HWND of the window.

Any help is appreciated

thanks

Copyright 2005-08 www.BigResource.com, All rights reserved