Solved

Ruby - InputBox

Posted on 2007-11-29
13
774 Views
Last Modified: 2010-05-18
Hello
Is it possible to get user input by using an Input Box e.g
Does a file exists - my code is as follows ........
puts "The file you are looking for does exist" if File.exist?("c:/Phil.txt")
.... then maybe get a message box to give the answer
I would like to get the user to enter c:/Phil.txt - is this possible and how

Regards
Phil

0
Comment
Question by:philsivyer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20374381
what do you mean with mesage box?
is this command line, web based or do you envisage to build a gui?
0
 

Author Comment

by:philsivyer
ID: 20374439
Command Line
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 20374555
try something like this

#puts the question
puts "Add a filename here:"

# read a line from the commandline
str1 = STDIN.gets

#test for file existence (write logic yourself)

#echo
puts "#{str1} does exist"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20374731
note that you can use the FileTest module for checking the existence of the file

#puts the question
puts "Add a filename here:"

# read a line from the commandline
str1 = STDIN.gets

#test for file existence
flag = FileTest::exists?(str1.strip)
#echo
if flag then
      puts "#{str1.strip} does exist"
else
      puts "#{str1.strip} does NOT exist"
end

cheers

Geert
0
 

Author Comment

by:philsivyer
ID: 20380612
Geert
When I run the code it opens a command screen and does not allow me to make an entry.
Phil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20380757
try running it in a commandscreen already
ruby mycode.rb
0
 

Author Comment

by:philsivyer
ID: 20380793
OK - it does not like it from ScITE - any ideas?

Phil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20380810
I wouldn't know how to get that working from within SciTE
I will look at it tonight
0
 

Author Comment

by:philsivyer
ID: 20380829
Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20380833
SciTE is for development by the way, is there a reason why you want to launch a program this way, other than for debugging?
0
 

Author Comment

by:philsivyer
ID: 20380928
Not really - I guess it's easier for me to cut and paste etc - and visually it looks easier on the eye.

Phil
0
 
LVL 14

Expert Comment

by:wesgarrison
ID: 21417764
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
Accept gertone's comment 20374555 as answer

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

wesgarrison Experts Exchange Cleanup Volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21447903
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
in ruby, how can I call notepad ? 4 548
db:create misreports database existence 1 464
Create an application - what tools to use? 4 616
Active Record and IBM_DB 3 793
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question