Page 1 of 2 1 2 LastLast
Showing results 1 to 10 of 11

Thread: Probleme bei Datentypkonvertierung in VB

  1. #1
    c.reps Gast

    Unglücklich Probleme bei Datentypkonvertierung in VB

    Hallo,

    ich möchte den Inhalt einer CSV-Datei einlesen.
    Der Inhalt ist wie folgt aufgebaut:

    STRING; REAL-Zahl; REAL-Zahl; REAL-Zahl; REAL-Zahl; REAL-Zahl;
    da ich später REAL-Zahlen vom Panel aus an die Steuerung überegeben möchte.

    ich lese die CSV-Datei Zeile für Zeile ein mit
    Line Input #1, var
    jetzt gibt es ja die Funktion split() hierfür habe ich eine Variable in VB angelegt
    Dim x As String

    hab dann in VB folgenden Code
    x=split(var, ";")

    nun weiße ich kann ich ja über
     xyz = x(0)
    wert1 = x(1)
    wert2= x(2)
    wert3 = x(3)
    wert4 = x(4)
    wert5 = x(5)

    zuweisen. wert1 bis 5 sind aber immernoch String und Real gibt es in VB nicht!

    Kann ich meine Werte trotzdem irgendwie nach Real bekommen? Wenn ja wie?

    Vielen Dank im voraus.

    lg
    c.reps

  2. #2
    flajoso Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    Hi,

    can you post in English? Maybe i can help you.
    Regards

  3. #3
    c.reps Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    ok, i try it in english.

    i want to import the content of an csv-file
    the content is built-on like
    STRING; REAL-Zahl; REAL-Zahl; REAL-Zahl; REAL-Zahl; REAL-Zahl;

    i read the content row for row with the funktion:

    Line Input #1, var

    so the content of one row stands in var

    then i split var with the function

    x=split(var, ";")
    and i get the values x(0),x(1),x(2),x(3),x(4),x(5) these are also of the typ String

    now my problem, i want x(1),x(2),x(3),x(4),x(5) as Real typ
    how can i make this?

  4. #4
    flajoso Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    Try this:

    dim test as double
    
    test = Val(x(1))

    Regards,

  5. #5
    c.reps Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    hy flajoso,
    thanks for your post.

    i found the val()- function, but i have another problem.
    in zenon i have a variable x_pos of typ real,
    and in vb i have the variable
    dim xpos as double
    xpos=val(...)

    next in vb i declare
    thisProject.Variables.Item("x_pos").Value =a

    for test display i have a messagebox
    msgbox thisProject.Variables.Item("x_pos").Value

    there i became "0"

    do you know where my mistake is?

    thx
    c.reps

  6. #6
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Probleme bei Datentypkonvertierung in VB

    @c.reps:

    which zenOn Version do you use?
    If you are using zenOn versions >= 6.22 the reading of variable values is restricted.

    Please check the "Revision text.pdf" at page 17 which is located on the zenOn DVD under ...\Information\ENGLISH\Revision texts

    Direct VBA read access on variables is only possible if the variable has been registered in
    the driver (advised) and if it has a value, i.e. if IsOnline() is true . Simple spontaneous
    queries (requests) are no longer possible.
    The following functions of the “Variable” object return an error if this is not the case:
    • Value
    • StatusValue
    • StatusExtValue
    • StatusString
    • LastUpdateTime
    • LastUpdateTimeMilliSeconds
    This means that existing projects will no longer run in the Runtime after the conversion, as
    the functions mentioned above will fail. The following solutions are available:
    1. Define an online container for all affected variable accesses.
    Advantage: The variables are only requested if you really need them.
    Disadvantage: Increased programming effort.
    2. Set “DDE active” in the group “Additional settings” of the variable properties
    for all affected variables.
    Advantage: Easy to perform.
    Disadvantage: The driver continuously requests all variables.
    For working with Variable Online Containers see also http://www.copadata.com/forums/showthread.php?t=41

    Regards,
    Herbert

  7. #7
    flajoso Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    Hi c.reps,

    i made a simple test and works fine.
    In Zenon i defined two variables:

    StringVar - STRING
    rReal - REAL

    then i called them to VBA, and manipulate them as needed, then i wrote again the new value in rReal.




    Dim dd As Double     ' my Double var, inside VBA
    Dim sVar As Variable  ' my string var inside VBA
    Dim rVar As Variable  ' my real var inside VBA
    
    Set sVar = thisProject.Variables.Item("StringVar")  ' bringing Zenon var to VBA var
    Set rVar = thisProject.Variables.Item("rReal")   ' same here
    
    
    dd = Val(sVar.Value) ' now i have the number value of the string Var
    
    rVar.Value = dd + 3.5323 ' just to check real values..

    Then i check the "Numerical Value" of rReal (rVar inside VBA) and its the add between number_value_of_string_var + 3.5323 ..


    hope it helps...
    regards,

  8. #8
    c.reps Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    hi flajoso,

    i think i'm to stupid for this.
    it doesn't work at my laptop.
    as attachment i have a simple test project, if you have time, it would be nice when you could look over it.

    i declared the 2 variables in zenon both are intern values
    sString of type String
    here i set the initial value to 200.3 and remance to initial value

    rReal of type Real

    at both "dde active" is set

    p.s.: i use zenon 6.20 sp1 build 0 as testversion, because we think about whether we buy zenon or moviconx

    cheers
    c.reps
    Attached Files Attached Files

  9. #9
    c.reps Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    ok, i found something out
    here is the code
    Public Sub tets()
    Dim dd As Double     ' my Double var, inside VBA
    Dim sVar As Variable  ' my string var inside VBA
    Dim rVar As Variable  ' my real var inside VBA
     
    Set sVar = thisProject.Variables.Item("sString")  ' bringing Zenon var to VBA var
    Set rVar = thisProject.Variables.Item("rReal")   ' same here
     
     
    dd = Val(sVar.Value) ' now i have the number value of the string Var
    MsgBox dd  [B][COLOR="Red"]' -> here a msgbox opens, where where dd value is diplayed[/COLOR][/B]
    
    rVar.Value = dd + 3.5323 ' just to check real values..
    MsgBox rVar.UserValue  [B][COLOR="Red"]' -> here a msgbox opens, where where "0" is diplayed[/COLOR][/B]
    
    rVar.UserValue = dd + 3.5323 ' just to check real values..
    MsgBox rVar.UserValue [B][COLOR="Red"]' -> here a msgbox opens, where the value of  dd+ 3.5323 is diplayed[/COLOR][/B]
    
    End Sub
    
    Public Sub ok()
    MsgBox "ok"
    
    End Sub

    what is the different between *.Value and *.UserValue?

    cheers
    c.reps

  10. #10
    robertf Gast

    Default Re: Probleme bei Datentypkonvertierung in VB

    @All

    Hi! I think the problem ist that easy, that you not thought about it...

    I have taken a look at the project, the String variable is declared with a length of 5 characters,
    so "200.3" is the maximum of characters for the string variable...

    The REAL variable is declared from "-1.00" to "1.00", so all values outside this range are ignored by zenon...

    You have to set the Range and Signal Parameters for example from -10000.000000" to "10000.000000" (Messbereich/Signalauflösung).
    To get more than 2 decimals, you also have to change the parameter (Nachkommastellen).

    After you change the Parameters of the REAL variable, the sample from flajoso will work!

Posting Rules

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