Reading Command Parameters
Have you ever wanted to click a file and open it? If your program is associated with a specified file type, or you select file(s) and drag them onto the exe icon of your app then this code is for you. It reads the parameters when the form is loaded using by getting the "Command". This code can get each file dragged or clicked on. If you just use the command statement you will get something like this "c:\george.bmp c:\ben.bmp f:\mydoc.doc". This code seperates each file and uses another sub to open it.
Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
'Code created by Jonathan Jarvis - Jman 'Email: [email protected] 'as of now this will require a listbox with a name of "List1" Private Sub getfiletoopen(filename As String) List1.AddItem filename End Sub Private Sub Form_Load() 'create variables Dim howlong, n As Integer, c As String 'give variables values c = Command n = 1 For howlong = Len(Command) To 1 Step -1 ' start loop statement If Mid(c, n, 1) = " " Then 'check to see if It should seperate commands getfiletoopen Mid(c, 1, n - 1) 'pick out the command from line only Mid(c, 1, n - 1) is the command file c = Right(c, Len(c) - n) 'change command and get rid of last handled file n = 0 'reset letter to 0 End If n = n + 1 'increment to next letter Next howlong 'go on to next letter 'takes care of last command line or 1st one if only one file is to be opened If c <> "" Then ' checks to see if there is a 1st or last command getfiletoopen c ' you can change this to load your file or command. c is the command parameter of the last file End If End Sub // This program is a puzzle where one needs to find a number between 1 to 100 which is generated by computer. //============================================================================================================// // This program helps us to know how to generate random numbers // //============================================================================================================// // If you want to compile this code in VC++ then name this as <filename>.cpp // If you want to compile this code in Unix then name this as <filename>.C (capital C) // Includes #include <iostream.h> #include <stdlib.h> #include <time.h> // Main Function int main() { // Prototypes void heading(); int nGuessedNum; // stores computer number int nInputNum; // stores inputted nubmer int nInd; // Index char nGotIt='n'; // Flag to indicate Success char nChoice='y'; // stores user choice // Loop while(nChoice=='y') { heading(); // Displays Heading nGotIt=' '; // Initailize a seed for random number generation using current time srand(static_cast<unsigned>(time(NULL))); // Increases randomness to get effective random numbers for(nInd=1;nInd<=10;nInd++) rand(); // Generate Computer number // formala : lower_range + (int) ( 1 + (lower_range + upper_range) * rand() / (RAND_MAX + 1.0)); // here 1.0 is used to get a double value, so that the random number varies nGuessedNum=1 + (int) (100 * rand()/(RAND_MAX + 1.0)); // This loop allows user to get the computer number in 5 chances for(nInd=1;nInd<6;nInd++) { cout<<"\n\n\t\tThis is Your Chance No = "<<nInd; cout<<"\n\t\tEnter the number between 1 to 100 :-"; cin>>nInputNum; // if your number is greater than computer's number if(nInputNum>nGuessedNum) cout<<"\n\t\tYour Number is Greater than Computer Number"; // if your number is lesser than computer's number else if(nInputNum<nGuessedNum) cout<<"\n\t\tYour Number is Lesser than Computer Number"; // if your number is equal to computer's number else { cout<<"\n\t\tHip Hip Hurray.... You have guessed the correct number"; nGotIt='y'; break; } } // if user cannot guess the computer's number in 5 chances then if(nGotIt!='y') { cout<<"\n\t\tOpps, Your chances are over "; cout<<"\n\t\tThe computer number is = "<<nGuessedNum; } // Do u want to continue cout<<"\n\n\t\tDo you want to play again [y/n] ?"; cin>>nChoice; } return 0; } // Heading which will displayed void heading() { cout<<"\t\tWelcome to the Game of Guessing...."; cout<<"\n\n\t\tThe computer has guessed a number between 1 to 100"; cout<<"\n\t\tYou have to the find the number. And you have 5 chances.."; cout<<"\n\t\tGet Set Go ..."; }