Jump to content

BLuFeNiX

Active Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by BLuFeNiX

  1. Yes, I know it is best to initialize with the needed variables, but in some cases you need a variable to be global, and you may need to reassign it later. I showed a break in code with an ellipse, but I probably should have made that clearer. Thank you for the advice. Thank you, also.
  2. In Java (as well as C++ an most other high-level languages) there is a feature called "type-casting" in which a variable of one type (double, float, etc) can be represented as another type (int, long, etc), or vice-versa. My question is: Which of the following is more efficient code, and why? int a; int b; double c; ... a = b = (int) (c = 0); int a; int b; double c; ... a = b = 0; c = 0; I predict that the second can be executed faster because initializing variables on the same line probably doesn't speed it up in the first place, but I'd just like to know everyone's thoughts. Thanks.
  3. got it. Sub Main Call GetSchoolLinksFrom_BCPS End Sub Sub GetSchoolLinksFrom_BCPS 'Initialize everything - this assumes a maximum of 4000 links on a page - increase it if you need to have more. 'Also, remember that this is a zero based array. Dim iexplore, page, linkCount, debugmode Dim linkArray(4000) debugmode = True linkCount = 0 'Now that everything is initialized, open the browser (assumes all browser windows are closed) TestedApps.iexplore.Run Set iexplore = Sys.Process("iexplore") Set page = iexplore.Page("*") 'Now go the specified webpage - note the ToURL function will automatically wait before continuing Call page.ToURL("http://www.bcps.org/") 'Click the schools link Call page.document.all.schools.Click page.Wait 'Call the super special procedure to find all the <a> tags. 'The debugmode will make things be logged or not as it finds each link. Call FindAllLinks(page.document.all, linkCount, linkArray, debugmode) if debugmode Then if linkCount>0 Then Log.Message("Total links found:" & linkCount) Log.Message("First link found:" & linkArray(0)) 'The first link is ALWAYS zero Log.Message("Final link found:" & linkArray(linkCount-1)) 'Remember this is a zero based array so subtract 1 from linkCount Else Log.Message("No links were found at this webpage:" & page.URL) End if End if 'From here you can do whatever you need to withthe linkArray() 'Finally close all the browsers TestedApps.CloseAll End Sub Sub FindAllLinks(d, lc, l, dbg) 'This routine should find all a href links in a page. It assumes you are using the DOM model. 'p = page to search thru 'lc = Number of links found 'l = array of the links found 'dbg = flag to say if you want things logged as they are found for debugging Dim i if dbg then Log.Message("Started searching... Number of Child Objects:" & d.ChildCount) lc = 0 For i = 0 To (d.ChildCount - 1) if d.Child(i).tagname <> "A" Then if dbg then Log.Message("Child(" & i & ") is not <a> tag. It has a tagname of '" & d.Child(i).tagname & "'.") Else l(lc)=d.Child(i).href lc=lc+1 if dbg then Log.Message("Link #" & lc & " - Child(" & i & ") is a href='" & d.Child(i).href & "'.") End if Next End Sub
  4. Hi all. I recently aquired an internship at the Department of Technology, in Timonium, MD, working for the BCPS school system. One of my jobs is to create scripts with a software called TestComplete. This creates a user-simulation that can be used to test if a system still works correctly after an update. For one of the scripts I need to find out if a link to download a .mw2 file is present on a page, and navigate to it. I assume the best way to do this would be to set the URLs on the page to an array, and check them against the string ".mw2", and when a comparison is found, go to that page. How do I do this? Here is my VBscript so far: (keep in mind I have never written VBscript before yesterday, any improvements are welcome) Sub Main ' Enter your code here. End Sub Sub Test1 Dim page Dim all Dim textbox dim bodyText dim searchResult dim downloadResult dim linkResult searchTerm = "compass" 'this will be queried using the CBTIA page's search engine searchString = "Compass Rose" 'this will be searched for after the searchTerm is queried TestedApps.iexplore.Run Set page = Sys.Process("iexplore").Page("http://www.bcps.org/") Call page.document.all.Offices.Click(37, 8) 'Please wait until download completes: "http://www.bcps.org/offices/" page.Wait page.document.all.Item(248).Click 'Please wait until download completes: "http://www.bcps.org/offices/oit/" page.Wait page.document.all.Item(129).Click 'Please wait until download completes: "http://www.bcps.org/apps/CBTIA/" page.Wait Set all = page.document.all Call all.ddlGradeLevel.ClickItem("3") Set textbox = all.txtKeyword Call textbox.Click(25, 10) Call textbox.Keys(searchTerm) all.btnSearch.Click 'Please wait until download completes: "http://www.bcps.org/apps/CBTIA/default.aspx" page.Wait searchResult = SearchPage(searchString, page)'sets to TRUE if searchString was found Set iexplore = Sys.Process("iexplore") page.document.all.Item(283).Click 'Please wait until download completes: "http://www.bcps.org/apps/CBTIA/cbtia.aspx?id=4154" page.Wait linkResult = FindLink(page) If linkResult = True Then downloadResult = DownloadCheck(iexplore) End If End Sub Function SearchPage(searchString, page) bodyText = page.document.all.Item("body").innerHTML If InStr(bodyText, searchString) > 0 Then Log.Message("Found!") SearchPage = TRUE Else Log.Warning(searchString + " was not found.") SearchPage = FALSE End If End Function Function DownloadCheck(iexplore) If iexplore.Window("#32770", "File Download").Exists < 0 Then 'did a download window appear? Log.Message("Found!") iexplore.Window("#32770", "File Download").Window("Button", "Cancel").ClickButton Else Log.Warning("File was not found! No .mw2 present") End If End Function Function FindLink(page) set urls = page.document.all.tags("a") 'THIS IS THE LINE THAT SHOULD CREATE THE ARRAY BUT IT DOESN'T WORK For x = 0 to (urls.length)-1 If InStr(urls(x).innerHTML, ".mw2") > 0 Then FindLink = TRUE 'page.document.all.Item(263).Click 'click on .mw2 link Set edit = Sys.Process("iexplore").IEFrame(0).Window("Edit", "", 1) edit.wText = urls(x).innerHTML Call edit.Keys("[Enter]") Exit Function End If Next FindLink = FALSE Log.Warning("Link to .mw2 Not Found!") End Function The code that navigates was automatically generated, I wrote the other functions, loops, etc. Please help!
  5. Hey guys, I've Googled around a bit and can't find anything useful. I need to run a program as a certain user. The username, password, and path to the executable should be built in to the code. Can anyone give me the most simplified code possible to achieve this? Thanks.
  6. Thanks guys, I was unaware that I had to show passing by reference in the function's prototype. Oh, and I do use Ubuntu as my main OS, and am trying to code more using the Eclipse IDE in linux but I'm in a C++ class at my highschool that uses VC++ so for now it will be easier to just use that.
  7. Hey guys, I recently moved into c++ from autoit and I'm working on a game called Nim. I haven't finished the logic for it quite yet, but I will worry about that later. When I try to compile what I have so far I get these errors: 1>------ Build started: Project: Nim2, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>Linking... 1>main.obj : error LNK2019: unresolved external symbol "void __cdecl computerTurn(int,int * const,int)" (?computerTurn@@YAXHQAHH@Z) referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol "void __cdecl playerTurn(int,int,int * const)" (?playerTurn@@YAXHHQAH@Z) referenced in function _main 1>E:\STUFF\My Code\C++\Projects\Nim2\Debug\Nim2.exe : fatal error LNK1120: 2 unresolved externals 1>Build log was saved at "file://e:\STUFF\My Code\C++\Projects\Nim2\Nim2\Debug\BuildLog.htm" 1>Nim2 - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== here is the code: #include <iostream> //input and output #include <time.h> //random seed using namespace std; void dispBoard(int, int[]); void playerTurn(int, int , int[]); void computerTurn(int, int[], int); int winCheck(int[], int); void results(int); void main() { int pilenum = 4; int pile[4] = {1, 3, 5, 7}; srand(static_cast<int>(time(NULL))); //seed random number int playerID = rand() % 2 + 1; // generate random number (1 or 2) if(playerID == 1) { cout << "Player will go first." << endl; playerTurn(pilenum, playerID, pile); } else { cout << "Computer will go first." << endl; } while(winCheck(pile, pilenum) != 1){ dispBoard(pilenum, pile); computerTurn(playerID, pile, pilenum); dispBoard(pilenum, pile); playerTurn(pilenum, playerID, pile); }; results(playerID); } void dispBoard(int pilenum, int pile[]) { for(int x = 0; x < pilenum; x++) { for(int i = pile[x]; i > 0; i--) { cout << "*"; } cout << endl; } } void playerTurn(int pilenum, int &playerID, int pile[]) { if(winCheck(pile, pilenum) != 0) { playerID = 1; int x = 0; int y = 0; cout << "Which pile? "; cin >> x; cout << "How many? "; cin >> y; if(x > 0 && x <= pilenum && y > 0 && y <= pile[x]) { pile[x] -= y; } } } void computerTurn(int &playerID, int pile[], int pilenum) { if(winCheck(pile, pilenum) != 0) { playerID = 2; int x = 0; int y = 0; while(1){ srand(static_cast<int>(time(NULL))); //seed random number x = rand() % pilenum + 1; y = rand() % pile[x] + 1; if(y != 0) { break; } }; pile[x] -= y; cout << "Computer took " << y << " from pile " << x << "." << endl; } } int winCheck(int pile[], int pilenum) { int y = 0; for(int x = 0, y = 0; x < pilenum; x++) { y += pile[x]; } return y; } void results(int playerID) { if(playerID = 1) { cout << "YOU LOSE." << endl; } else { cout << "YOU WIN!!!" << endl; } } Any ideas? Please don't clean the code unless it's neccesary to fix the problem. Thanks.
  8. okay, lets try this again, but next time you answer, lets have just a little bit more feeling, and maybe some constructive context. aaaaand. action. but, seriously, what is wrong with it?
  9. well, would you (or anyone else) be willing to contribute a more logical way of solving this problem? My original code, before trying to keep the string from having a trailing "\", is as follows string dirString; cout << "Where? "; getline(cin, dirString); // get directory input from user int start = dirString.find("\\"); // int length = string("\\").size(); // change "\" to "\\" so that it can be read correctly. dirString.replace(start, length, "\\\\"); // _chdir(dirString.c_str()); // change current working directory system("cd"); // print new directory using system() call is there anything non-sensical about that part?
  10. thanks for te help : ) , but it seems to have fixed one thing and broken another : ( string dirString; cout << "Where? "; getline(cin, dirString); // get directory input from user int i = strlen(dirString.c_str()); // set i to the length of dirString while (dirString.at(i)=='\\') { // is the last character of dirString a "\" ? dirString = dirString.substr(0, dirString.length() - 1); // remove last character in string i--; //THIS WAS MISSING FROM LOGIC BEFORE }; int start = dirString.find("\\"); // int length = string("\\").size(); // change "\" to "\\" so that it can be read correctly. dirString.replace(start, length, "\\\\"); // system("cd"); // print new directory using system() call _chdir(dirString.c_str()); // change current working directory now i get this popup error when i run the program: Unhandled exception at 0x7c812aeb in BLuCMD.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0012fb90.. it does that no matter what i type into the directory prompt...help!?
  11. I just started c++ programming a few days ago, and am trying to make my own command prompt just for fun. It's about 95% complete, and I need to fix the cd command. string dirString; cout << "Where? "; getline(cin, dirString); // get directory input from user int i = strlen(dirString.c_str()); // set i to the length of the dirString while (dirString.at(i)=="\\") { // is the last character of dirString a "\" ? THIS IS WHERE THE ERROR IS dirString = dirString.substr(0, dirString.length() - 1); // if so, remove last character in string }; int start = dirString.find("\\"); // int length = string("\\").size(); // change "\" to "\\" so that it can be read correctly. dirString.replace(start, length, "\\\\"); // system("cd"); // print new directory using system() call _chdir(dirString.c_str()); // change current working directory the errors are as follows: error C2446: '==' : no conversion from 'const char *' to 'int' There is no context in which this conversion is possible error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]' can somebody help me out? (if you decide to optimize the code, please post it seperate from the fixed code, thanks)
  12. #include <GUIConstants.au3> $Form1 = GUICreate("CoD2", 179, 36, 304, 162) $Label1 = GUICtrlCreateLabel("R == Start", 8, 8, 64, 17) $Label2 = GUICtrlCreateLabel("F == Pause", 104, 8, 62, 17) $Label3 = GUICtrlCreateLabel(":", 80, 8, 7, 17) GUISetState(@SW_SHOW) HotKeySet("r", "Start") HotKeySet("f", "Pause") Global $Pause = 3 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If $Pause = 1 Then Send("c") Sleep(200) Send("{SPACE}") EndIf WEnd Func Pause() $Pause = 3 EndFunc Func Start() $Pause = 1 EndFunc This way you can check to see if the GUI is closed while the macro is running.
  13. i know i can disclude floppy checking, but that kinda defeats the purpose of the script, partially anyway.
  14. Desk Drive v1.0 Straight from the support forum! if you have a floppy drive you may get VERY VERY annoyed... #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.11.12 (beta) Author: BLuFeNiX (formerly known as HackerZer0) Script Function: Add shortcut to removable media to desktop. #ce ---------------------------------------------------------------------------- Opt("OnExitFunc", "_CLEANUP") While 1 For $i = 65 to 90 If DriveStatus (Chr($i) & ":") = "READY" then If DriveGetType(Chr($i) & ":") = "Fixed" then Continueloop If NOT FileExists(@desktopDir & "\Drive (" & Chr($i) & ").lnk") then FileCreateShortcut(Chr($i) & ":",@DesktopDir & "\Drive (" & Chr($i) & ").lnk") Else FileDelete(@desktopDir & "\Drive (" & Chr($i) & ").lnk") EndIf Next Sleep(1000) WEnd Func _CLEANUP() FileDelete(@desktopDir & "\Drive (*).lnk") EndFunc
  15. that's pretty cool, i like watching it in mspaint
  16. I was wondering the same thing.. *confused*
  17. That is an AMAZING script!!! If it wasn't free... I'd buy it! lol j/k (well, cause i did make it)
  18. You should add support for reading the MBR or BIOS if at all possible. Detect boot loaders (ntldr, lilo, grub, etc) or BIOS model/ver (phoenix-award, AMI, etc) Good job though!
  19. Thats's a pretty cool concept.. Nice work
  20. Nice job
  21. No source? Most people on this forum aren't going to try your program, they like to look over the script themselves and lean from it, or check it for malicious or bad code before they run it. Post the source and i will try.
×
×
  • Create New...