Options

Script help needed.

DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
HI I would like some ideas,

What I want to do is to produce a simple program that will auto create some script for me.

Now I was thinking of using Access but this is a bit of an over kill I think and would rely on the user having access installed on there PC. So I was wondering how else to do it.

It boils down to this,

I have the information below

Refnumber: 12345
Location: UK
Data center: 500

Switch 1: adam
port G1/2
vlan 50

port g1/3
vlan 60

switch 2: dave
port g1/7
vlan 5

port 1/9
vlan 7


I want to create a form that I can enter this date in to and click a button to get out the full script as you would apply to the switch / router. with all the standard commands needed to achive it. So it is a case or inputting data and then creating a formated document at the end.

The number of switchs and ports are varibable so it would require you to be able to add and change these entry fields.

But what would people suggest I used? I want a GUI for users. This is a pet project I want to do :)

Access??
VB??
Java??
Other?

Cheers

Aaron
  • If you can't explain it simply, you don't understand it well enough. Albert Einstein
  • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.

Comments

  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Aaron,

    We could do this with SQL Server Express, Silverlight, and a WCF service. It could run on a local PC running IIS. No need even for a server. I would love to help you with something like this.

    I attached an example of a GUI I created for a SharePoint list that tracks disk space. I was really just playing around, but thought it looked nice. It all depends on how you really want to progress. But I would love to lend you a hand. Just don't tell WebMaster - I still owe him a TechLab on PowerShell that I can't seem to focus on...
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Aaron,

    We could do this with SQL Server Express, Silverlight, and a WCF service. It could run on a local PC running IIS. No need even for a server. I would love to help you with something like this.

    I attached an example of a GUI I created for a SharePoint list that tracks disk space. I was really just playing around, but thought it looked nice. It all depends on how you really want to progress. But I would love to lend you a hand. Just don't tell WebMaster - I still owe him a TechLab on PowerShell that I can't seem to focus on...

    Hi there,

    Thank you very much for the kind offer. Let me explain a bit more of the backgoround to this.

    for an example what happens is that Company X ask us to provision ports for one of there servers in data center Y rack Z

    we go away and find out the switchs in that rack, what ports are avalible and waht vlans, spp, duplex thoses ports need to be configured for.

    so we have the infomation some thing like ..
    Company Ref:
    Our Ref:
    Sever name:
    Location:
    Data Center:
    Rack:

    Switch: port: vlan: Speed: Duplex
    Switch: port: vlan: Speed: Duplex
    Swithc: port: vlan: Speed: Duplex

    We then take this and write a script that looks some thing like
    ==================================================
     
    Company ref: 12345
    Our Ref: 12345
     
    Location: UK
    Data Center:London
    Rack: AD076
     
    Servername: Derek
    Switch1: SAS45
    Switch2: SAS46
     
    ===========================================
     
    Log on to switch: SAS45
     
    conf t
     
    int g0/4
    description ***Derek_pro***
    switch port access
    Switch port access VLAN 50
    No shut
    exit
     
    int g0/4
    description ***Derek_Backup***
    switch port access
    switchport access VLAN 120
    speed 100
    duplex full
    no shut
    exit
    exit
     
    show int status
     
    wr mem..
     
    ============================================
     
    Log on to switch: SAS46
     
    conf t
     
    int g0/4
    description ***Derek_pro***
    switch port access
    Switch port access VLAN 50
    No shut
    exit
    exit 
     
    show int status
     
    wr mem
     
    ============================================
    

    this is then passed to the monkeys (sorry implementation team) to carry out the actuly work.

    what I am looking to do is create a form that people can enter in the switch, port, vlan information and click a button to create the script for the current values the user has filled in.

    So it actuly does not need a data base behind it, as once its done we dont save any thing apart from the script.

    I was hoping to used something that means anyone can run it from there PC, so a excatuable self contained program.

    This is actuly only one case, other tasks would need different scripts so idealy if i can get this inplace I will expand on it to included all our tasks. making the process of scripting much faster than the current copy and pasting in to an existing template.
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Got it. The reason I suggest the DB is to ensure that what they are asking for is actually correct. If server X exists, but is in rack Z not rack Y the user should not be allowed to enter that. If it is backed by a DB it would be easy for an admin to go in and change the rack/server settings. But that might be over kill. I don't know. This would be presented via IIS, so it's a web site. Any one on an Internet accessible PC with a browser that supports Silverlight (IE, Chrome, FireFox, Safari) would be able to access it. Easties scenario would be a simple form the user fills out (no validation of data) and a text file is generated and emailed to a distribution list for the team in question.

    Especially if you consider SharePoint integration there is a ton that could be done with this pretty easily. The reason I suggest making it web based is that any updates that need to be done to it don't need to be installed on the client and all clients have the most recent version. I'm suggestig Silverlight because it's what I know.

    But if you are keeping configuration data (like multiple script templates) they need to be stored some place. Why not use a DB? It's more scalable than configuration files on a disk.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Another idea would be a simple web form and a CGI/Perl script that assemples the data and mails the script. That would be pretty simple to configure. The down side being you have to trust that what the user is entering is correc - but that is going to be the case to some extent any way you go.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Easties scenario would be a simple form the user fills out (no validation of data) and a text file is generated and emailed to a distribution list for the team in question.

    This would be what I have in mind for first base.. there are thousands of rack / switchs / locations and I dont have access to the full list so the data base would have to be populated by people filling in the form.

    there may also be issues of storing customer data of there site, at the moment we cant remove there documentation, so creating a data base on our systems containg the information might be a problem.

    On the other hand as we build up the data it could be very usefull, to store it....
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Do you have any issue with it being done in Silverlight? I could knock something out pretty quickly. If you think plain old HTML with Perl would be better - I have not touched Perl in a few years and it might be easier for you to learn enough to modify a free script.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Wow well either is good. I would like to use this as a way to learn scripting, as apart from some basic batch files, basic, and very some basic VB stuff I havent any experince. And my C++ experince are many years ago. icon_sad.gif

    I am thinking maybe HTML is actuly not a bad Idea as a place to start from. web based forms ?? I like it :)
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Mmm yes HTML forms :) I think I could make one of them up :) then its just a case of what to use as a back end on the server to deal with the information.

    I think I will make up the form how I want it in the next few days and then think about how I deal with creating the script :)

    Cheers
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Altering a simple form mail script in Perl should not be too hard for you. Perl is a pretty cool language. Very good to know if you are getting into Linux and it can help on the Windows admin side too. Though PoSh is more ideal there, of course.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    just reading through a few forms and scripts

    only issues is now how to deal with dynamic Forms,

    but i will deal with that later :) what i mean is I want to click on a button on the page to create a new switch / port text entry box

    then I have to deal with that in terms of the perl script understanding the new entries

    but start simple and make it complex :)
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    OK so here's my form...

    I know very basic but :)

    So all I want is when I press the submit button it open as new page with the reformatted text I have entered in to the form fields.

    So I am looking for a nice example of a Perl or PHP scripting that does this.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" >
    <title>Switch Form</title>
    
    <style>
    <!--
    h1 { font-family: Arial, sans-serif; font-size: 30px; }
    h2 { font-family: Arial, sans-serif; font-size: 18px; }
    
    body,p,b,i,em,dt,dd,dl,sl,caption,th,td,tr,u,blink,select,option,form,div,li { font-family: Arial, sans-serif; font-size: 12px; }
    -->
    </style>
    
    </head>
    <body bgcolor="#ffffff">
    <h1 align="center">  Port Provision Scripting</h1>
    <p align="left"><u><strong><font size="4">Refrence 
    Numbers</font></strong></u>  </p>
    <p align="left">  GCM Ref: <input maxlength="10" 
    name=GCMref>&nbsp;&nbsp;&nbsp;&nbsp; SRM Ref: <input maxlength="10" 
    name=SRMref>&nbsp;&nbsp;&nbsp; CHM Ref: <input maxlength="10" name="CHMref">  </p>
    <p align="left"><strong><u><font size="4">Location 
    Details</font></u></strong>  </p>
    <p align="left">  Data Center: <input maxlength="15" 
    name=DataCenter>&nbsp; Hall: <input maxlength="10" name="Hall">&nbsp; 
    Rack:&nbsp;<input name="Rack">  </p>
    <p align="left">  Secure Server Farm ? <input value="SSF" 
    type=checkbox name=SSF_DMZ>&nbsp; If yes Number: <select size="1" 
      name=SSFnumber><option selected value=1>1</option> <option value="2">2</option> 
      <option value="3">3</option> <option value="4">4</option> <option 
      value=5>5</option> <option value="6">6</option> <option value="7">7</option> 
      &lt;\SELECT&gt;</select>  </p>
    <p align="left"><input value="Submit" type="submit" name="Submit">  </p>
    <p align="left">  First Switch Name: <input maxlength="10" 
    name=SWAname>  </p>
    <p align="left">  Port: &nbsp;<input 
    style="WIDTH: 57px; HEIGHT: 22px" size=7 name=SWAP1>&nbsp; Vlan: <input 
    style="WIDTH: 55px; HEIGHT: 22px" size=7 
    name=SWAP1VLAN>&nbsp;Speed:&nbsp;<select size="1" name="SWAP1Speed"><option 
      selected value=Auto>Auto</option> <option value="100">100</option> <option 
      value=1000>1000</option> <option value="10000">10000</option> 
    &lt;\SELECT&gt;</select>&nbsp;Duplex:&nbsp;<select size="1" 
      name=SWAP1Duplex><option selected value=Auto>Auto</option> <option 
      value=Full>Full</option> <option value="Half">Half</option> 
    &lt;\SELECT&gt;</select>  </p>
    <p align="left">  Port: &nbsp;<input 
    style="WIDTH: 57px; HEIGHT: 22px" size=7 name=SWAP2>&nbsp; Vlan: <input 
    style="WIDTH: 55px; HEIGHT: 22px" size=7 
    name=SWAP2VLAN>&nbsp;Speed:&nbsp;<select size="1" name="SWAP2Speed"><option 
      selected value=Auto>Auto</option> <option value="100">100</option> <option 
      value=1000>1000</option> <option value="10000">10000</option> 
    &lt;\SELECT&gt;</select>&nbsp;Duplex:&nbsp;<select size="1" 
      name=SWAP2Duplex><option selected value=Auto>Auto</option> <option 
      value=Full>Full</option> <option value="Half">Half</option> 
    &lt;\SELECT&gt;</select>  </p>
    <p align="left">  &nbsp;</p>
    <p align="left">  Second Switch Name: <input maxlength="10" 
    name=SWBname>  </p>
    <p align="left">  Port: &nbsp;<input 
    style="WIDTH: 57px; HEIGHT: 22px" size=7 name=SWBP1>&nbsp; Vlan: <input 
    style="WIDTH: 55px; HEIGHT: 22px" size=7 
    name=SWBP1VLAN>&nbsp;Speed:&nbsp;<select size="1" name="SWBP1Speed"><option 
      selected value=Auto>Auto</option> <option value="100">100</option> <option 
      value=1000>1000</option> <option value="10000">10000</option> 
    &lt;\SELECT&gt;</select>&nbsp;Duplex:&nbsp;<select size="1" 
      name=SWBP1Duplex><option selected value=Auto>Auto</option> <option 
      value=Full>Full</option> <option value="Half">Half</option> 
    &lt;\SELECT&gt;</select>  </p>
    <p align="left">  Port: &nbsp;<input 
    style="WIDTH: 57px; HEIGHT: 22px" size=7 name=SWBP2>&nbsp; Vlan: <input 
    style="WIDTH: 55px; HEIGHT: 22px" size=7 
    name=SWBP2VLAN>&nbsp;Speed:&nbsp;<select size="1" name="SWBP2Speed"><option 
      selected value=Auto>Auto</option> <option value="100">100</option> <option 
      value=1000>1000</option> <option value="10000">10000</option> 
    &lt;\SELECT&gt;</select>&nbsp;Duplex:&nbsp;<select size="1" 
      name=SWBP2Duplex><option selected value=Auto>Auto</option> <option 
      value=Full>Full</option> <option value="Half">Half</option> 
    &lt;\SELECT&gt;</select>  </p>
    </body>
    </html>
    

    So thinking something like this code snip it jigged around a bit.
    # Read the standard input (sent by the form):
    read(STDIN, $FormData, $ENV{'CONTENT_LENGTH'});
    # Get the name and value for each form input:
    @pairs = split(/&/, $FormData);
    # Then for each name/value pair....
    foreach $pair (@pairs) {
    	# Separate the name and value:
    	($name, $value) = split(/=/, $pair);
    	# Convert + signs to spaces:
    	$value =~ tr/+/ /;
    	# Convert hex pairs (%HH) to ASCII characters:
    	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    	# Store values in a hash called %FORM:
    	$FORM{$name} = $value;
    }
    
    #The code then goes on to generate the thank-you page
    
    sub thank_you {
    
    print "Content-type: text/html\n\n";
    
    print <<endstart;
    
    	<html>
    	<head>
    	<title>Thank You</title>
    	</head>
    	
    	<body bgcolor="#ffffff" text="#000000">
    	
    	<h1>Thank You</h1>
    	
    	<p>Your feedback has been received. Thanks for sending it.</p>
    	
    	<hr>
    	
    	
    EndStart
    
    	print "<p>You wrote:</p>\n";
    	print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n"; print
    	
    &lt; <endhtml;
    	
    	 body <> EndHTML exit(0); } </body></html>
    

    But is there a neater way to take the form values and created a webpage from them?

    Cheers

    DevilWAH
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    willhi1979willhi1979 Member Posts: 191
    DevilWAH wrote: »
    But is there a neater way to take the form values and created a webpage from them?

    The code isn't very clean. You could put each tag on a line and tab it to the appropiate level in terms of the nesting. You could also put the Options in a database and use a query to recurse through the records and create the options tags.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    willhi1979 wrote: »
    The code isn't very clean. You could put each tag on a line and tab it to the appropiate level in terms of the nesting. You could also put the Options in a database and use a query to recurse through the records and create the options tags.

    Please read previous messages and you will see why he does not want to do that.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Sundely worked out how easy this is :)

    at the moment the script is a bit static, but with a few "if" statments, nested varibles and loops I can make the code a lot simpler and efficent.

    Cheers for the pointers

    Out of intrested can any one help with dynamicaly unhidding fileds in a form? cheers

    DevilWAH
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    OK who can help with perl script

    From my form I get the varible
    $FORM{'SWAP1'}
    $FORM{'SWAP2'}
    $FORM{'SWAP3'} etc etc

    and I am using the print statment to do some thing like

    print "int $FORM{'SWAP1'}<br>\n";

    so say SWAP1 = g0/3 i get the out put of.

    int g0/3

    what I want to be abel to do is call a sub routine that i can set a varible to a number and then nest that inside the varible above.

    eg

    i=2
    print "int $FORM{'SWAP$i'}<br>\n";

    so for each switch and port I pass the switch number and port number to the sub routine and reuse the code.

    but I cant work out how to do this? How can i return the value of the $form{} varibable using another varibable when calling it?

    Cheers

    DevilWAH
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    OK got a bit further
    sub writeconfig
    ## Takes passed varibles and creates config
    {
       ## populates sub varibles from passed vlaues
       $s=$_[0];
       $p=$_[1];
       ## Writes config to screen
       $switchP="SW$s\P$p";
       print "<p>int $FORM{$switchP}<br>\n";
       print "switch port access $FORM{$switchP.VLAN}<br>\n";
       print "Speed $FORM{$switchP.Speed}<br>\n";
       print "Duplex $FORM{$switchP.Duplex}<br>exit\n";
    }
    

    running this works and printing $switchP assuming $s = A and $p = 1 gives

    $switchP=SWAP1 which is what I want

    however it does comes up with the error that the escape \P is not recanlised and passed??

    trying

    $switchP="SW$sP$p";

    and it comes out as eaquling 1 as it sees the varible with in SW$sP$$P as "$sP"

    Can any one tell me the correct syntax for this ?

    Cheers

    DevilWAH
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Well finaly achived waht I wanted :) actuly was a lot more stright forward than I thought it would be.

    And what started as some long draw out code I managed tidy up quite a lot

    849d1296138258-script-help-needed-form-screen-shot.jpg

    below the finaly output from the script. Still need to tidy up the formatting but 99% there.
    [B][U][FONT=Times New Roman]PORT PROVISIONING IMPLEMENTATION SCRIPT [/FONT][/U][/B]
    [B][FONT=Times New Roman]Scripted by:[/FONT][/B][FONT=Times New Roman] DevilWAH on the 27/01/2011[/FONT]
    [FONT=Times New Roman][B]To be implemented on: [/B]29/01/2011 [/FONT]
    [B][FONT=Times New Roman]GCM Refrence:[/FONT][/B][FONT=Times New Roman] GSM002365 [B]SRM Refrence:[/B] SRM003659:021 [/FONT]
    [B][FONT=Times New Roman]CHM refrence:[/FONT][/B][FONT=Times New Roman] CHM0000954874 [/FONT]
    [B][FONT=Times New Roman]Data Center: [/FONT][/B][FONT=Times New Roman]London[B] Hall:[/B] 452 [B]Rack:[/B] B34[/FONT]
     
    [FONT=Times New Roman][B]For Server:[/B] mailpub [B]in secure server farm:[/B] N/A [/FONT]
    [FONT=Times New Roman]======================================================================================================= ======================================================================================================= [/FONT]
    [FONT=Times New Roman]You can use the following show commands to display details for indivual ports. [/FONT]
    [B][FONT=Times New Roman]On Switch lon452sa34 use [/FONT][/B]
     
    [FONT=Times New Roman]sh int g0/3 status [/FONT]
    [FONT=Times New Roman]sh int g0/4 status [/FONT]
    [FONT=Times New Roman]sh int g0/5 status [/FONT]
     
    [FONT=Times New Roman][B]On Switch lon452sa35 use [/B][/FONT]
     
    [FONT=Times New Roman]sh int g0/3 status [/FONT]
    [FONT=Times New Roman]sh int g0/4 status [/FONT]
    [FONT=Times New Roman]======================================================================================================= [/FONT]
    [B][FONT=Times New Roman]Log on to Switch:[/FONT][/B][FONT=Times New Roman] lon452sa34 [/FONT]
    [FONT=Times New Roman]conf t [/FONT]
    [FONT=Times New Roman]int g0/3[/FONT]
    [FONT=Times New Roman]description mailpub[/FONT]
    [FONT=Times New Roman]switchport access vlan 45[/FONT]
    [FONT=Times New Roman]Speed Auto[/FONT]
    [FONT=Times New Roman]Duplex Auto[/FONT]
    [FONT=Times New Roman]exit [/FONT]
    [FONT=Times New Roman]int g0/4[/FONT]
    [FONT=Times New Roman]description mailpub[/FONT]
    [FONT=Times New Roman]switchport access vlan 50[/FONT]
    [FONT=Times New Roman]Speed Auto[/FONT]
    [FONT=Times New Roman]Duplex Auto[/FONT]
    [FONT=Times New Roman]exit [/FONT]
    [FONT=Times New Roman]int g0/5[/FONT]
    [FONT=Times New Roman]description mailpub_ilo [/FONT]
    [FONT=Times New Roman]switchport access vlan 150[/FONT]
    [FONT=Times New Roman]Speed 100[/FONT]
    [FONT=Times New Roman]Duplex Full[/FONT]
    [FONT=Times New Roman]exit [/FONT]
    [FONT=Times New Roman]exit [/FONT]
     
    [FONT=Times New Roman]wr mem [/FONT]
    [FONT=Times New Roman]======================================================================================================= [/FONT]
    [B][FONT=Times New Roman]Log on to Switch:[/FONT][/B][FONT=Times New Roman] lon452sa35 [/FONT]
    [FONT=Times New Roman]conf t [/FONT]
    [FONT=Times New Roman]int g0/3[/FONT]
    [FONT=Times New Roman]description mailpub[/FONT]
    [FONT=Times New Roman]switchport access vlan 46[/FONT]
    [FONT=Times New Roman]Speed Auto[/FONT]
    [FONT=Times New Roman]Duplex Auto[/FONT]
    [FONT=Times New Roman]exit [/FONT]
    [FONT=Times New Roman]int g0/4[/FONT]
    [FONT=Times New Roman]description mailpub[/FONT]
    [FONT=Times New Roman]switchport access vlan 51[/FONT]
    [FONT=Times New Roman]Speed Auto[/FONT]
    [FONT=Times New Roman]Duplex Auto[/FONT]
    [FONT=Times New Roman]exit [/FONT]
    [FONT=Times New Roman]exit [/FONT]
     
    [FONT=Times New Roman]wr mem [/FONT]
    [FONT=Times New Roman]=======================================================================================================[/FONT]
    
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    Good work. +rep for you! Would you add it to the script repo?
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Good work. +rep for you! Would you add it to the script repo?

    if you can remind me where it is lol
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Dam I must post this script! its on my work laptop though so next time I am on that I will try to remember to upload it (need to edit some of the infomation out as its becoem a little client based)

    But moving on I am thinking of recodeing it in Visual Basic as I want to make it stand alone, so if any one has a code snip-it to create a file, and write to it I wouldn't be great-full to see it.

    Or maybe I will get back in to C++...

    Dam just to many choises!
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    I am looking for a bit of code to work out some maths
    users can currently input a start and finsh time on my form.
    at the moment this can be in any from such as

    02:30
    17:41
    3:10

    is there any way using standard HTMl form codes to force them to enter a string that is exactly 5 in lenth? (eg. 00:00 )

    or would I have to use drop down lists?

    I dont want to use client sided scripting or frames if i can help it.

    secondly is there a way to split the string in perl baed on the ":" they will enter?

    what i want to do is some thing like.

    take start and end time.

    05:34 and 06:25

    and work out each in terms of minutes.

    easy way is ( number before : X 60 ) + number after

    so start time = (5 X 60 ) + 34 = 334
    and end time = (6 X 60) + 25 = 385

    time taken = 385 - 334 = 51.

    And forget all of this I just worked it out using the split function :)

    I sure this is a round about way to do things but works for me :)
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Here we are if any one wants it :)

    form fields are tstart and tend and the $FORM{} varible has been populated eairler in the script. Lots of extra print commands to show whats happening
    print "$FORM{'tstart'}<br>$FORM{'tend'}}<br>";
    @stimes = split(':', $FORM{'tstart'});
    @etimes = split(':', $FORM{'tend'});
    print "$stimes[0]\n";
    print "$etimes[0]\n\n";
    $smin = ($stimes[0] * 60) + $stimes[1];
    $emin = ($etimes[0] * 60) + $etimes[1];
    print "$smin \n";
    print "$emin \n\n";
    $time = $emin - $smin;
    print "$time";
    
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    tierstentiersten Member Posts: 4,505
    DevilWAH wrote: »
    is there any way using standard HTMl form codes to force them to enter a string that is exactly 5 in lenth? (eg. 00:00 )
    maxlength attribute. e.g. <input type="text" maxlength="5" name="time" />
    DevilWAH wrote: »
    secondly is there a way to split the string in perl baed on the ":" they will enter?

    take start and end time.

    05:34 and 06:25

    and work out each in terms of minutes.

    easy way is ( number before : X 60 ) + number after

    so start time = (5 X 60 ) + 34 = 334
    and end time = (6 X 60) + 25 = 385

    time taken = 385 - 334 = 51.
    Don't do it like that. Use Date::Manip.
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    tiersten wrote: »
    maxlength attribute. e.g. <input type="text" maxlength="5" name="time" />

    Hi, this is what I did, but it still does not stop some one entering the string as less than 5. However...


    Don't do it like that. Use Date::Manip.

    it seems this does not care if it is 5:65 or 05:65 :)

    cheers for that, I am not sure if this is a bit OTT at the moment as from what I read Date::Manip is a large module in its self, and for what I want the code I wrote works fine.

    However I still going to code it with this just to see how it works :)

    Cheers
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
Sign In or Register to comment.