Sign in to follow this  
Followers 0
GHGjelstad

Parsing a Excel CSV-file into variables

4 posts in this topic

Hi there,

Have run into a small challenge.

I need to read from a CSV-file, delimited with ; .

The separator character (:) is fixed.

My csv-file contans 1000+ lines of data, length of text between separators is not fixed.

Example from csv-file.

Hostname;Sitenumber;IPaddress;Std-Gateway;Netmask;SiteName;Customer Address;Zipcode;City;Phonenbr.;EDI-code;EDI-Number;2;81;SERVICEDESK REF SITE;TEST;0;0;XXX;3;4;Customer;7;13;10;

Optimally I want to read the "Hostname" into a GUI-listbox where i can choose the one host to install.

The info from the line containing the chosen hostname, should be read into variables, for further use in configuring the host.

If anyone could point me in the right direction here then it would be great.

/Glenn

Share this post


Link to post
Share on other sites



Hi there,

Have run into a small challenge.

I need to read from a CSV-file, delimited with ; .

The separator character (:) is fixed.

My csv-file contans 1000+ lines of data, length of text between separators is not fixed.

Example from csv-file.

Hostname;Sitenumber;IPaddress;Std-Gateway;Netmask;SiteName;Customer Address;Zipcode;City;Phonenbr.;EDI-code;EDI-Number;2;81;SERVICEDESK REF SITE;TEST;0;0;XXX;3;4;Customer;7;13;10;

Optimally I want to read the "Hostname" into a GUI-listbox where i can choose the one host to install.

The info from the line containing the chosen hostname, should be read into variables, for further use in configuring the host.

If anyone could point me in the right direction here then it would be great.

/Glenn

<{POST_SNAPBACK}>

i had to do something similar, creating a dynamic combo box... i always mess up when i do links in here, so if you'd like to see my thread about my adventure in dynamic combo boxes, just click my name over there and check my topics... i think i've only started 1 or two of them, and one is named 'dynamic combo box'

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

If anyone could point me in the right direction here then it would be great.

Here are some functions. Please read the help file and the samples therein. FileReadLine(), StringSplit(), _GUICtrlListAddItem

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Hi there,

Have run into a small challenge.

I need to read from a CSV-file, delimited with ; .

/Glenn

<{POST_SNAPBACK}>

Here is a function I made to read fields from .csv files (after reading the file to an array), it is simple and only works on the most simple files, but change the "," to a ";" and it might get you started.

exit_program is just a function to perform some cleanup if an error is detected.

;between_commas will return the the information between which_comma and which_comma + 1
;for example, if which_comma = 0, it will return everything before the first comma
;it needs a string and which comma (integer) as arguments
func between_commas($the_string, $which_comma)
    dim $current_comma = 0
    dim $left_bound = 0
    dim $temp_string
    dim $right_bound = stringlen($the_string)
    dim $character_position
    
;This section finds the left bounds that we actually want
    $character_position = 0
    while($current_comma < $which_comma)
        if(stringmid($the_string,$character_position,1) = ",") then
            $current_comma = $current_comma + 1
        EndIf
        $character_position = $character_position + 1
        
        if($character_position > $right_bound) Then
            exit_program("function betwen_commas is trying to find comma: " & $which_comma & " but only found: " & $current_comma & " commas.  Exceeded length of array which was " & $right_bound & ".  Possibly a corrupt file or an error in the script.")
        EndIf
        
    WEnd
    
    $temp_string = " "
    while($character_position < $right_bound + 1)
        if(stringmid($the_string, $character_position, 1) = ",") Then
            $character_position = $right_bound + 1
        Else
            $temp_string = $temp_string & stringmid($the_string, $character_position, 1)
            $character_position = $character_position + 1
        EndIf
    WEnd
    return $temp_string
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0