🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Check list and file reading.

User: "Jouher_20929"
Altair Community Member
Updated by Jouher_20929

I have written a code to create checklist to read Id and names from a text file.


{BEGIN LEGEND}
 Entity #        Title
        1     abc                                                           
        2     efs                                                                
        3     afdsf                                                                     
        4     xzcH                                                                       
        5     sdsafd                                                                  
        6     wqerwf                                                                  
 

During file reading I want to skip first two lines and take lines from 3 to 10. What change should be made in the code?

Similarly, in the checklist, when I tick and press OK, the corresponding ID should be stored in a variable. WHat should I do?

 

The code is given below!!!!!!!!!!!!!!!!

 

 

 

 

 

 


$w hide apply;

set recess [$w recess]

 


proc ::texample::OnSelect {W S c} {

    puts [info level 0]

}

 

hwtk::selectlist $recess.sl -stripes 1 -selectmode multiple -selectcommand '::texample::OnSelect %W %S %c'

pack $recess.sl -fill both -expand true;

$recess.sl columnadd id -text Id

$recess.sl columnadd entities -text 'Section Name'

#####################

set fileName [tk_getOpenFile]
set fp [open $fileName r]
set ::lines [split [read $fp] '\n']


set i 0

foreach line $::lines {

set ID [string range $line 7 8]
set NM [string range $line 14 20]

$recess.sl rowadd row$i -values


  1. incr i

    }
    close $fp;                         

}

$w post

Find more posts tagged with

Sort by:
1 - 15 of 151
    User: "Imoto"
    Altair Employee
    Updated by Imoto

    Hi,

     

    If you want to ignore the first 2 lines, you just write 'gets' twice.

     

    Example:
    set fh [open [tk_getOpenFile] r];
    gets $fh null;
    gets $fh null;
    while {! [eof $fh]} {
     gets $fh cl;
     puts $cl;
    }
    close $fh

     

    Thanks,
    Imoto

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    Hi,

     

    If you want to ignore the first 2 lines, you just write 'gets' twice.

     

    Example:
    set fh [open [tk_getOpenFile] r];
    gets $fh null;
    gets $fh null;
    while {! [eof $fh]} {
     gets $fh cl;
     puts $cl;
    }
    close $fh

     

    Thanks,
    Imoto

     i want to read from 3rd to 41st line only.

    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

     i want to read from 3rd to 41st line only.

    For each line, make a counter. So your code looks like

     if {$counter >=3 && $counter <=41} {    # do something }

     

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    For each line, make a counter. So your code looks like

      if {$counter >=3 && $counter <=41} {    # do something }

     

    How to make a counter using my code.

    User: "Imoto"
    Altair Employee
    Updated by Imoto

    Just replace the 'while' to 'for'.

     

    set fh [open [tk_getOpenFile] r];
    gets $fh null;
    gets $fh null;
    for {set i 0} {$i < 39} {incr i} {
     gets $fh cl;
     puts $cl;
    }
    close $fh
     

    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

    How to make a counter using my code.

     

     set i 1 foreach line $::lines { 	if {$i>=3 && $i<=41} { 		#do something with $line 	} 	incr i } 

     

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    My final code is given below. Now, if I select check list i want to store IDs in varaible. What to do?

     


    <?xml version="1.0" encoding="UTF-8"?>image.thumb.png.919320ca88be7a5749c9e7b2c3678926.png

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    @tinh Please help for last Query

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi,

    define selectcommand as below

    proc ::texample::OnSelect {W S c} {

       set IDs {}

       foreach row $S {

          lappend IDs [dict get [$W rowcget $row -values] id]

       }

       puts 'Selected IDs=[set ::var_SelectedIDs $IDs]'

    }

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    @tinh can you tell me how can I create a similar window outside hM. What will be the change? Please help me.

    Thanks for your kind support.

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi Jouher,

    You need to load hwtk package by these commands:

     

    set AltairHome 'C:/Altair/2017'

    if {[file join $AltairHome hw tcl] ni $::auto_path]} {

        lappend ::auto_path [file join $AltairHome hw tcl]; #because hwtk needs some packages in this

        lappend ::auto_path [file join $AltairHome hw tcl hwtk];

    }

    package require hwtk

    source [file join $AltairHome hw tcl hwtk init.tbc]

    #then you can create its widgets:

    hwtk::selectlist .sl ...

    ...

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    Hi Jouher,

    You need to load hwtk package by these commands:

     

    set AltairHome 'C:/Altair/2017'

    if {[file join $AltairHome hw tcl] ni $::auto_path]} {

        lappend ::auto_path [file join $AltairHome hw tcl]; #because hwtk needs some packages in this

        lappend ::auto_path [file join $AltairHome hw tcl hwtk];

    }

    package require hwtk

    source [file join $AltairHome hw tcl hwtk init.tbc]

    #then you can create its widgets:

    hwtk::selectlist .sl ...

    ...

    I did not understand set altair home. Please explain. While I run as batch using wish tool, its showing cant run packages.

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    @tinh When I execute this command

     


    'source [file join $AltairHome hw tcl hwtk init.tbc]' Its throwing error.

     


    can't rename to 'xml::tdomparser': command already exists

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi, just ignore that command!

    I use v13.0 so i need it.

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    @Tinh, It works.

    could you tell me how I will add to my selectlist a filter option. Like, if I press 'A' and enter 'ok', all names with A will come.