conditional - Ruby/Shoes cannot get numeric value from selection of list_box -


i'm trying integer conditional statement based on selection on list_box. cannot make work. also, able remove @acuity = para. code based on this: list_box won't use default value on startup - shoes.

shoes.app :title=> 'procedural', :width => 300, :height => 200   @list_box = list_box :items => ["1- ad lib", "2- assist of sb", "3- assist of 1", "4- assist of 2"]                             button 'compute'         @acuity.text = @list_box.text   if @acuity == "1- ad lib"         @mobility = 11   elsif @acuity == "2- assist of sb"         @mobility = 22   elsif @acuity == "3- assist of 1"     @mobility = 33   elsif @acuity == "4- assist of 2"     @mobility = 44   end        end      @acuity = para      end 

it's not clear goal is. display @mobility somewhere? assigning value @mobility variable nothing.

shoes.app    @choice_map = {     "1- ad lib"       => 11,     "2- assist of sb" => 22,     "3- assist of 1"  => 33,     "4- assist of 2"  => 44   }    para "choose item:"   @my_listbox = list_box(:items => @choice_map.keys)     button 'compute'     @mobility = @choice_map[@my_listbox.text]   end  end 

to prove @mobility contains correct value, need display value somewhere:

shoes.app    @choice_map = {     "1- ad lib"       => 11,     "2- assist of sb" => 22,     "3- assist of 1"  => 33,     "4- assist of 2"  => 44   }    @my_listbox = list_box(items: @choice_map.keys)    @my_para = para 'show computed results here'    button 'compute'     @mobility = @choice_map[@my_listbox.text]     @my_para.text = @mobility   end  end 

your code works fine minor change:

shoes.app :title => 'procedural', :width => 300, :height => 200   @list_box = list_box :items => ["1- ad lib", "2- assist of sb", "3- assist of 1", "4- assist of 2"]                          @my_para = para 'show computed results here'  button 'compute'   @acuity = @list_box.text   #<---change here    if @acuity == "1- ad lib"     @mobility = 11   elsif @acuity == "2- assist of sb"     @mobility = 22   elsif @acuity == "3- assist of 1"     @mobility = 33   elsif @acuity == "4- assist of 2"     @mobility = 44   end    @my_para.text = @mobility  end 

if don't need button:

shoes.app    @choice_map = {     "1- ad lib"       => 11,     "2- assist of sb" => 22,     "3- assist of 1"  => 33,     "4- assist of 2"  => 44   }    para "choose item:"    @default = "2- assist of sb"   @mobility = @choice_map[@default]    @my_listbox = list_box(items: @choice_map.keys, choose: @default) |list|     @mobility = @choice_map[list.text]   end  end 

the block given list_box() executed onchange, have set initial value @mobility.

you think following able retrieve initial value in listbox:

shoes.app    @choice_map = {     "1- ad lib"       => 11,     "2- assist of sb" => 22,     "3- assist of 1"  => 33,     "4- assist of 2"  => 44   }    para "choose item:"    @my_listbox = list_box(items: @choice_map.keys) |list|     @mobility = @choice_map[list.text]     @my_para.text = @mobility   end    @mobility = @choice_map[@my_listbox.text]   @my_para = para @mobility  end 

but apparently listbox not exist until after app block finishes executing, can't retrieve @my_listbox.text inside app block.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -