Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

custom list

carlcocarlco Member Posts: 9
Have an app in VB6 against Oracle. Want to iterate through a number of records and insert sequential alphanumeric values into database. For example, "Sample X" is the most recent sample in the db, and has location value of "BOX1000", position "A5".

When I add a new sample, I will pull out those two location values and give the new sample values that represent that location + 1 ("BOX1000","A6"), etc. When I reach "A12", the next location will be ("BOX1000", "B1"), up to "G12", then ("BOX1001","A1"). You should see the pattern.

BOX1000 G11
BOX1000 G12
BOX1001 A1
BOX1001 A2
etc.

I can program this as a "Select Case", simply capturing the variables and assigning a new value based on that, but would require an extensive list(have simplified it for this question). Is there a way in VB6 to create some kind of function, or custom list, that would "know" what value to assign based on the current value, or must I specifically lay it all out in code?

Thanks.

Comments

  • infidelinfidel Member Posts: 2,900
    : Have an app in VB6 against Oracle. Want to iterate through a number of records and insert sequential alphanumeric values into database. For example, "Sample X" is the most recent sample in the db, and has location value of "BOX1000", position "A5".
    :
    : When I add a new sample, I will pull out those two location values and give the new sample values that represent that location + 1 ("BOX1000","A6"), etc. When I reach "A12", the next location will be ("BOX1000", "B1"), up to "G12", then ("BOX1001","A1"). You should see the pattern.
    :
    : BOX1000 G11
    : BOX1000 G12
    : BOX1001 A1
    : BOX1001 A2
    : etc.
    :
    : I can program this as a "Select Case", simply capturing the variables and assigning a new value based on that, but would require an extensive list(have simplified it for this question). Is there a way in VB6 to create some kind of function, or custom list, that would "know" what value to assign based on the current value, or must I specifically lay it all out in code?

    There are probably lots of ways you could do this. My first inclination would be to break up the two keys into four so your record would be something like:

    NAME = "Sample X"
    LOC_PREFIX = "BOX"
    LOC_NUMBER = 1000
    POS_PREFIX = "A"
    POS_NUMBER = 12

    Then you could write a function like

    [code]
    Public Type SampleItem
    name As String
    loc_prefix As String
    loc_number As Integer
    pos_prefix As String
    pos_number As Integer
    End Type

    Public Function IncrementCoordinates(ByVal itemIn As SampleItem) As SampleItem

    Dim itemOut As SampleItem

    'increment the position number
    itemOut.pos_number = itemIn.pos_number + 1

    'if the position number is too high, set it to 1
    'and increment the position prefix (A to B, B to C, etc)
    If itemOut.pos_number > MAXPOSITIONNUMBER Then
    itemOut.pos_number = 1
    itemOut.pos_prefix = Chr(Asc(itemIn.pos_prefix) + 1)

    'if the position prefix is too high, set it to A
    'and increment the location number
    If Asc(itemOut.pos_prefix) > MAXPOSITIONPREFIX Then
    itemOut.loc_number = itemIn.loc_number + 1
    itemOut.pos_prefix = "A"
    End If
    End If
    itemOut.loc_prefix = itemIn.loc_prefix

    IncrementCoordinates = itemOut

    End Function
    [/code]

    I wrote all of this off the top of my head so I haven't tested it at all, but it's an option I would consider myself.
  • Shawn CarterShawn Carter Member Posts: 0

    ________ // http://forcoder.org // free ebooks and video tutorials about / PL/SQL, Swift, Python, MATLAB, Delphi, Visual Basic, Assembly, Objective-C, Scratch, Visual Basic .NET, Perl, R, PHP, Java, C++, C, C#, Ruby, JavaScript, Go Bash, Hack, Transact-SQL, ML, Logo, Erlang, Lisp, Alice, VBScript, Julia, Kotlin, SAS, D, Clojure, Fortran, Ada, Scheme, Scala, ABAP, LabVIEW, Rust, Awk, Lua, Dart, COBOL, FoxPro, Apex, Prolog, Crystal, F# / _______

Sign In or Register to comment.