您好,請原諒我對我很不好英語首先是...Vb.net呼叫Class1.enum
我不習慣與結構或枚舉的工作...
我有很多在我的項目班,我試圖組織。
我的類Duree將包含多個枚舉或結構。
我想能夠調用不同的枚舉或結構。
並在關聯的結構上構建請求。
RepairList.vb
Public Class RepairList
Dim Tool As New Tools
Dim uuu As String = Tool.Find("C:\Data\1\" & Form1.TextBox2.Text & ".txt", "ProductType")
' Now uuu contains iPhone7,2
uuu = uuu.Replace(",", "")
uuu = uuu.Replace("i", "I")
uuu = uuu.Replace(" ", "")
uuu = uuu.Replace("P", "p")
' Now uuu contain Iphone72
Dim p As Devices.Device ' Class Devices --> Structure --> Device
Dim info As Reflection.FieldInfo = p.GetType().GetField(uuu)
Dim az As Object = info.GetValue(p)
' Now az contains Iphone 6
Dim toto As Object
toto = az
toto = toto.Replace(" ", "")
' Now toto contain Iphone6 the Name of the enum i woul catch in Duree
Dim test As String = myCheckbox.Name ' now test contains AntenneWifi
Dim value As Integer
value = CInt([Enum].Parse(GetType(Duree.Iphone6), test))
End Class
Devices.vb
Public Class Devices
Public Structure Device
Const Iphone41 = "Iphone 4S"
Const Iphone51 = "Iphone 5"
Const Iphone52 = "Iphone 5"
Const Iphone53 = "Iphone 5C"
Const Iphone54 = "Iphone 5C"
Const Iphone61 = "Ihpone 5S"
Const Iphone62 = "Iphone 5S"
Const Iphone71 = "Iphone 6 Plus"
Const Iphone72 = "Iphone 6"
Const Iphone81 = "Iphone 6S"
Const Iphone82 = "Iphone 6S Plus"
Const Iphone84 = "Iphone SE"
Const Iphone91 = "Iphone 7"
Const Iphone92 = "Iphone 7 Plus"
Const Iphone93 = "Iphone 7"
Const Iphone94 = "Iphone 7 Plus"
End Structure
End Class
Duree.vb
Public Class Duree
Public Enum Iphone5
'Define the Repair Time For each action.
AntenneWifi = 35
Batterie = 15
BtnVolDown = 45
BtnVolUp = 45
BtnHome = 20
BtnPower = 35
CableWifiBth = 35
CamAr = 30
MotherBoard = 30
FullScreen = 20
ScreenOnly = 40
HPExt = 35
HPInt = 25
SimLevier = 35
NappeHomeLong = 30
NappeBtnPower = 45
NappeFacetime = 30
NappeVolVibr = 40
PlaqueProtectLCD = 30
PriseJack = 40
SimTray = 2
Vibreur = 25
End Enum
Public Enum Iphone6
'Define the Repair Time For each action.
AntenneWifi = 35
Batterie = 15
BtnVolDown = 45
BtnVolUp = 45
BtnHome = 20
BtnPower = 35
CableWifiBth = 35
CamAr = 30
MotherBoard = 30
FullScreen = 20
ScreenOnly = 40
HPExt = 35
HPInt = 25
SimLevier = 35
NappeHomeLong = 30
NappeBtnPower = 45
NappeFacetime = 30
NappeVolVibr = 40
PlaqueProtectLCD = 30
PriseJack = 40
SimTray = 2
Vibreur = 25
End Enum
End Class
我把這裏只有2枚舉,但我有更多的Duree
類
所以在RepairList.vb我將在下面一行
value = CInt([Enum].Parse(GetType(Durée.Iphone6), test))
更換Duree.Iphone6
通過類似
value = CInt([Enum].Parse[GetType("Duree+" & toto), test))
但我不能找到正確的語法。
這裏是什麼,我已經看過之前
和許多其他..
感謝的很多,如果你能幫助我的概述
我真的不明白你在這裏試試。你從一個變量中獲得一個字符串作爲枚舉的名字,然後你嘗試設置與一個枚舉值關聯的整數或者你想要做什麼? –
對不起,我不得不編輯主要帖子,以更準確。 – moi
我想他打算通過字符串找到一個枚舉。順便說一句,你爲什麼想要它?如果您的程序需要選擇,Enum是防止錯誤輸入的最佳方法... – Karuntos