PDA

View Full Version : Combination data types



Neverine
05-07-2021, 09:45 AM
Hello,

its possbile make combination of data types? my solution doesnt work and i ddnt find on internet how to do..


'data type product 1-3
Dim DOC As String: DOC = "Product 1"
Dim DOK As String: DOK = "Product 2"
Dim DOB As String: DOB = "Product 3"
'data type product 4-6
Dim KC As String: KC = "Product 4"
Dim KK As String: KK = "Product 5"
Dim KB As String: KB = "Product 6"
'data type product 7-9
Dim SCo As String: SCo = "Product 7"
Dim SKl As String: SKl = "Product 8"
Dim SCi As String: SCi = "Product 9"
'data type combination
Dim Sna As String: Snack = SCo Or SKl Or SCi
Dim Dor As String: Dortik = DOC Or DOK
Dim Kor As String: Korpus = KK Or KB


'start
If (set1.Value = KC And (set1.Value = K1 Or set12.Value = K2) And set13.Value = T2) Then
MsgBox "X"


'next
ElseIf ((set1.Value = DC Or set1.Value = DK Or set1.Value = DCi Or set1.Value = DB Or set1.Value = DM) And set13.Value = Kor) Then
MsgBox "wrong"

SamT
05-07-2021, 11:46 AM
That example is too inconstant to understand. Both If statements use words not declared.

You might be looking for the VBA Type Statement


User-defined types are often used with data records, which frequently consist of a number of related elements of different data types.
The following example shows the use of fixed-size arrays in a user-defined type:
Type StateData
CityCode (1 To 100) As Integer ' Declare a static array.
County As String * 30
End Type

Dim Washington(1 To 100) As StateData
In the preceding example, StateData includes the CityCode static array, and the record Washington has the same structure as StateData.

Paul_Hossler
05-07-2021, 11:56 AM
1. These are 9 different products stored as 9 simple Strings -- OK



'data type product 1-3
Dim DOC As String: DOC = "Product 1"
Dim DOK As String: DOK = "Product 2"
Dim DOB As String: DOB = "Product 3"

'data type product 4-6
Dim KC As String: KC = "Product 4"
Dim KK As String: KK = "Product 5"
Dim KB As String: KB = "Product 6"

'data type product 7-9
Dim SCo As String: SCo = "Product 7"
Dim SKl As String: SKl = "Product 8"
Dim SCi As String: SCi = "Product 9"


2. These are 3 'other' variables - I'm guessing that Dim Sna should be Snack, etc



'data type combination
Dim Snack As String: Snack = SCo Or SKl Or SCi
Dim Dortik As String: Dortik = DOC Or DOK
Dim Korpus As String: Korpus = KK Or KB


3.
If (set1.Value = KC And (set1.Value = K1 Or set12.Value = K2) And set13.Value = T2) Then

What is set1, set2, and set3?
What is K1, K2, and T2?


4.
ElseIf ((set1.Value = DC Or set1.Value = DK Or set1.Value = DCi Or set1.Value = DB Or set1.Value = DM) And set13.Value = Kor) Then

What is DC, DK, DCi, DB, DM, Kor?


5. Just taking a guess



Option Explicit




Sub test()
Const Snack As String = "SCo#SKl#SCi#"
Const Dortik As String = "DOC#DOK#"
Const Korpus As String = "KK#KB#"

If InStr(Snack, "SKl#") > 0 Then
MsgBox "SKl is a Snack"
Else
MsgBox "SKl is not a Snack"
End If

MsgBox "SKl is " & IIf(InStr(Snack, "SKl#") > 0, "", "not ") & "a Snack"
MsgBox "KK is " & IIf(InStr(Snack, "KK#") > 0, "", "not ") & "a Snack"
End Sub





but if there's a lot, I'd build a mini-database on a worksheet and use that, but it's only a guess since it's not clear to me what you want to do

Neverine
05-08-2021, 02:33 AM
1. These are 9 different products stored as 9 simple Strings -- OK



'data type product 1-3
Dim DOC As String: DOC = "Product 1"
Dim DOK As String: DOK = "Product 2"
Dim DOB As String: DOB = "Product 3"

'data type product 4-6
Dim KC As String: KC = "Product 4"
Dim KK As String: KK = "Product 5"
Dim KB As String: KB = "Product 6"

'data type product 7-9
Dim SCo As String: SCo = "Product 7"
Dim SKl As String: SKl = "Product 8"
Dim SCi As String: SCi = "Product 9"


2. These are 3 'other' variables - I'm guessing that Dim Sna should be Snack, etc



'data type combination
Dim Snack As String: Snack = SCo Or SKl Or SCi
Dim Dortik As String: Dortik = DOC Or DOK
Dim Korpus As String: Korpus = KK Or KB


3.
If (set1.Value = KC And (set1.Value = K1 Or set12.Value = K2) And set13.Value = T2) Then


What is set1, set2, and set3?

set1,set2, and set3 are listbox with data from excel

)
What is K1, K2, and T2?
)
This is names for products upper its not part of code what i post here



4.
ElseIf ((set1.Value = DC Or set1.Value = DK Or set1.Value = DCi Or set1.Value = DB Or set1.Value = DM) And set13.Value = Kor) Then

What is DC, DK, DCi, DB, DM, Kor?
This also is names for products upper


5. Just taking a guess



Option Explicit




Sub test()
Const Snack As String = "SCo#SKl#SCi#"
Const Dortik As String = "DOC#DOK#"
Const Korpus As String = "KK#KB#"

If InStr(Snack, "SKl#") > 0 Then
MsgBox "SKl is a Snack"
Else
MsgBox "SKl is not a Snack"
End If

MsgBox "SKl is " & IIf(InStr(Snack, "SKl#") > 0, "", "not ") & "a Snack"
MsgBox "KK is " & IIf(InStr(Snack, "KK#") > 0, "", "not ") & "a Snack"
End Sub





but if there's a lot, I'd build a mini-database on a worksheet and use that, but it's only a guess since it's not clear to me what you want to do


---------------------------------------------------------
This seems to work
(Const Snack As String = "SCo#SKl#SCi#"
Const Dortik As String = "DOC#DOK#"
Const Korpus As String = "KK#KB#")


i have a 6 different listboxs, if i select all six conditions it start with first Elseif where are 3 condition


ElseIf (set1.Value = DC And set11.Value = K2 And set12.Value = T2 And settime.Value <= 12) Then (put here something like set21.value xxx(if nothing selected in textbox), set22.value xxx, set22.value xxx)?
MsgBox "L2 production"

ElseIf (set1.Value = DC And set11.Value = K1 And set12.Value = T2 And (set21.Value = Snack Or set21.Value = Korpus Or set21.Value = Dortik) And set22.Value = K1 And set23.Value = T1 And settime.Value <= 12) Then
MsgBox "different line for production"

Paul_Hossler
05-08-2021, 05:09 AM
i have a 6 different listboxs, if i select all six conditions it start with first Elseif where are 3 condition


ElseIf (set1.Value = DC And set11.Value = K2 And set12.Value = T2 And settime.Value <= 12) Then (put here something like set21.value xxx(if nothing selected in textbox), set22.value xxx, set22.value xxx)?
MsgBox "L2 production"

ElseIf (set1.Value = DC And set11.Value = K1 And set12.Value = T2 And (set21.Value = Snack Or set21.Value = Korpus Or set21.Value = Dortik) And set22.Value = K1 And set23.Value = T1 And settime.Value <= 12) Then
MsgBox "different line for production"

More details needed

Neverine
05-09-2021, 12:29 PM
More details needed
28438

Private Sub Generator_Click()

Dim D1 As String: D1 = "DK"
Dim D2 As String: D2 = "DS"
Dim D3 As String: D3 = "DC"
Dim D4 As String: D4 = "SCo"
Dim D5 As String: D5 = "SKl"
Dim D6 As String: D6 = "SCi"
Const X1 As String = "SCo#SKl#SCi#"
Const X2 As String = "DK#SKl#SCi#DC#DS#"

'first option
If (set1.Value = D1 And set2.Value = "L1" And set3.Value = "L1x" And settime.Value <= 12(if And set2x.Value = "L1 or L2" and ) Then
MsgBox "Production only on L1"
' something like this must be in (first option) for possibility to choice 6 options? (if set1x.Value = X2 And set2x.Value = "L1 or L2" and set3x.Value = "L1x or L2x" continue to next elseif)


Elseif (set1.Value = D1 And set2.Value = "L2" And set3.Value = "L1x" And settime.Value <= 12) Then
MsgBox "Production only on L2"

'this option doest happend still first option is correct

Elseif (set1.Value = D1 And set2.Value = "L1" And set3.Value = "L1x" And (set1x.Value = X1) And set2x.Value = "L1" And set3x.Value = "L1x" And settime.Value <= 12) Then
MsgBox "L1production continue on L2 production"
Else
MsgBox "Something is wrong"
End If
End Sub

SamT
05-09-2021, 02:29 PM
Bad syntax:
And set*.Value = "value1 or value2"
Must be
And (set*.Value = "value1" Or set*.Value = "value2")

This comment is incorrect
'this option doest happend still first option is correct

It should be
'this option doesn't happen unless first two IF Statements are false

I have tried, but with everything named so similar, ("set" + suffix, )I just can't wrap my head around your code. Too many sets. And you use 6 Variables, (D1 thru D6,) instead of using 6 short, real words, ("DK" thru "SCi".) It all makes it impossible for me to read your code.

Try organizing your code like

If Not settime.Value <= 12) Then
MsgBox"Something is wrong"
Exit sub
End If

If set1.Value = "DK" Then
If set3.Value = "L1x"
Option1
Option2
Option3
End if
If set3.value = "L2x" then 'Imaginary example
Option4
Option5
Option6
End if

ElseIf Set1.Value = "DS" Then
Etc

ElseIf Set1.Value = "DC" Then
Etc

ElseIf Etc

Else
MsBox"Something is wrong"
End If

Etc

Paul_Hossler
05-09-2021, 05:13 PM
I added CODE tags - you can use the [#] icon and paste your macro between

Your If/ElseIf/Then's were a little confusing

The way I ended up interpting wa that Set1.value and settime.value and set3.value all had to have a specific value in all cases

Instead of a long involved complicated nested bunch of If's, I've found that it's easier for me to have readable code by catching a failure right away; that's the 3 Goto ErrorExit statements




Option Explicit


Private Sub Generator_Click()


Dim D1 As String: D1 = "DK"
Dim D2 As String: D2 = "DS"
Dim D3 As String: D3 = "DC"
Dim D4 As String: D4 = "SCo"
Dim D5 As String: D5 = "SKl"
Dim D6 As String: D6 = "SCi"
Const X1 As String = "SCo#SKl#SCi#"
Const X2 As String = "DK#SKl#SCi#DC#DS#"

If set1.Value <> D1 Then GoTo ErrorExit
If settime.Value > 12 Then GoTo ErrorExit
If set3.Value <> "L1x" Then GoTo ErrorExit


If set2.Value = "L1" And (set2x.Value = "L1" Or set2x.Value = "L2") Then
MsgBox "Production only on L1"


ElseIf set2.Value = "L2" Then
MsgBox "Production only on L2"


ElseIf set2.Value = "L1" And InStr(X1, set1x.Value & "#") > 0 And set2x.Value = "L1" Then
MsgBox "L1 production continue on L2 production"
End If


Exit Sub


ErrorExit:
MsgBox "Something is wrong"
End If


End Sub