Consulting

Results 1 to 8 of 8

Thread: Combination data types

  1. #1
    VBAX Regular
    Joined
    May 2021
    Posts
    10
    Location

    Combination data types

    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"

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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.

    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    Last edited by Paul_Hossler; 05-07-2021 at 12:08 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    May 2021
    Posts
    10
    Location
    Quote Originally Posted by Paul_Hossler View Post
    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"

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    May 2021
    Posts
    10
    Location

    Post

    Quote Originally Posted by Paul_Hossler View Post
    More details needed
    descr.jpg
    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
    Last edited by Paul_Hossler; 05-09-2021 at 04:47 PM. Reason: Added CODE tags

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •