Ricky D Well-Known Member Licensed User Longtime User Mar 10, 2012 #1 If I have Code: Type tFare(TableID Int, FareDate As Long, AddingNew As Boolean) Type tShift(TableID Int, ShiftDate As Long, AddingNew As Boolean how would I write a sub to do something like Code: Sub Save(obj As Object, addingnew As Boolean If typeof(obj)=typeof(tFare) Then 'add or edit the Fare Dim f as tFare f = obj Msgbox(f.TableID,"") Else If typeof(obj)=typeof(tShift) Then 'add or edit the Shift End If End Sub Is there a way to check if an object is one of my types? I can't find anything like typeof regards, Ricky
If I have Code: Type tFare(TableID Int, FareDate As Long, AddingNew As Boolean) Type tShift(TableID Int, ShiftDate As Long, AddingNew As Boolean how would I write a sub to do something like Code: Sub Save(obj As Object, addingnew As Boolean If typeof(obj)=typeof(tFare) Then 'add or edit the Fare Dim f as tFare f = obj Msgbox(f.TableID,"") Else If typeof(obj)=typeof(tShift) Then 'add or edit the Shift End If End Sub Is there a way to check if an object is one of my types? I can't find anything like typeof regards, Ricky
Ricky D Well-Known Member Licensed User Longtime User Mar 10, 2012 #2 made a workaround : Code: Type tFare(TableID Int, FareDate As Long, AddingNew As Boolean) Type tShift(TableID Int, ShiftDate As Long, AddingNew As Boolean Code: Sub Save(obj as Object, thistype As String) If thistype="fare" Then Dim f As tFare If f.AddingNew Then 'add a new fare Else 'update existing fare End If Else If thistype="shift" Then dim s as tShift s = obj If s.AddingNew Then 'add a new shift Else 'update existing shift End If End If End Sub call it like this Code: Dim Fare As tFare Dim Shift As tShift Fare.Initialize Fare.TableID = 3 Fare.FareDate = DateTime.Now Fare.AddingNew = True Save(Fare,"fare") regards, Ricky Upvote 0
made a workaround : Code: Type tFare(TableID Int, FareDate As Long, AddingNew As Boolean) Type tShift(TableID Int, ShiftDate As Long, AddingNew As Boolean Code: Sub Save(obj as Object, thistype As String) If thistype="fare" Then Dim f As tFare If f.AddingNew Then 'add a new fare Else 'update existing fare End If Else If thistype="shift" Then dim s as tShift s = obj If s.AddingNew Then 'add a new shift Else 'update existing shift End If End If End Sub call it like this Code: Dim Fare As tFare Dim Shift As tShift Fare.Initialize Fare.TableID = 3 Fare.FareDate = DateTime.Now Fare.AddingNew = True Save(Fare,"fare") regards, Ricky
Erel B4X founder Staff member Licensed User Longtime User Mar 10, 2012 #3 You should use: Code: If obj Is tFare then dim t As tFare t = obj ... Upvote 0
Ricky D Well-Known Member Licensed User Longtime User Mar 11, 2012 #4 thanks Erel. Thats simplifies it :sign0142: regards, Ricky Upvote 0