Khishin 0 Newbie Poster

There is a ton of info in that tutorial now that I look into it and it might be a lot to digest at once.

For the moment, CTRL+F remedied that. :D
I'll be sure to read through it, though, as it seems to include a lot of interesting information.

Khishin 0 Newbie Poster

Thank you very much for the speed and helpfulness!

My working version of executeClass:

public static void executeClass(String path)
{
     try
     {
          Class c = Class.forName(path);
          Object o = c.newInstance();
          System.out.println("Class Loaded.");
     }
     catch(Exception e)
     {
          System.out.println("EXCEPTION");
     }
}
Khishin 0 Newbie Poster

I'm not sure if my title adequately explains what I want to do, so I'll provide a scenario.

I have two classes in a folder, one named UserInterface.class and another named HelloWorld.class, and the contents are as follows:

import java.util.Scanner;

public class UserInterface
{
     public static void main(String[] args)
     {
          Scanner kboard = new Scanner(System.in);
          System.out.print("Enter path of class to execute: ");
          String path = kboard.nextLine();
          executeClass(path);
          }

     public static void executeClass(String path)
     {
          //???
     }
}
public class HelloWorld
{
     public HelloWorld()
     {
          System.out.println("Hello World!");
     }
}

I want to be able to input "HelloWorld.class" when UserInterface.class is run, and have "Hello World!" printed to the screen. What I am having trouble doing is finding how to do this, specifically what would be in the executeClass method in this example.

Is this possible? And if so, can someone point me in the right direction?

I have searched the documentation on sun.com and if I understand the defineClass method of ClassLoader correctly, it seems to be promising if I were to read the contents of a class file into an array of bytes, but I'm not completely sure what I would do with the return, and the notation "protected final Class<?>" as the return type seems somewhat cryptic to me. (Why is it protected, why is it final, and what in the world does <?> mean?)

Thanks for any advice you can give!

Khishin 0 Newbie Poster

Well, I think what Chris was saying was to use the WHERE extension on my query so I don't have to use the while loop.

Khishin 0 Newbie Poster

The error is referred to execute time up to line 35.

It is very likely there is error in your php code (may be an endless loops etc). I suggest you use echo to display values in $contents (after line 15) and in $check (after line 33), before solving line 35.

I'm not quite sure that you close the mysql connection before call the results??

There was an endless loop, the page that set the cookie did not convert the username to lowercase before encrypting.

And it looks like you should close the connection as soon as possible to make it easier on the server so it doesn't have to keep listening for requests. TI think the query places the contents of the rows into $result rather than linking the two.

I don't understand your code at all. Why are you running a loop to check every record in the table for the value in the cookie? Why don't you just execute a query that checks for the existence of the value you are looking for and save yourself a lot of execution time and headaches?

Because that's all I knew to do. :sad:

Looking around, do you mean a query like this?

$query="SELECT name, password, md5 FROM users WHERE md5=$check";

Where I call the cookie into $check earlier and create a new column 'md5' with pre-calculated hashes?

And if I removed the first reference to the md5 column in the above, would it still be …

Khishin 0 Newbie Poster

Two questions here, the first is whether the following error refers to the command exceeding 60 seconds or the whole page taking over 60 seconds to execute.

"Fatal error: Maximum execution time of 60 seconds exceeded in /***/panel.php on line 35"

The code is as follows.

<html>
<head>Text</head>
<body>

<?

$loggedin=0;

$dbusername="*****";
$dbpassword="*****";
$database="*****";

if (isset($_COOKIE['sINFO'])) {

$contents=$_COOKIE['sINFO'];


mysql_connect(localhost,$dbusername,$dbpassword);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT name, password FROM users";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
$cancelwhile=0;
while ($i<$num && $cancelwhile==0) {
$check=mysql_result($result,$i,"name");
$check.=mysql_result($result,$i,"password");

$check=md5($check);

if ($contents==$check) {

echo ("Welcome back ".mysql_result($result,$i,"name"));
$cancelwhile=1;
$loggedin=1;

}

$i++;
if ($i=$num && $cancelwhile==1) {echo ("You are not logged in.");}

}



}else{
echo ("You are not logged in.");
}


if (loggedin==1) {

echo ("<br>Select an option.");

}


?>



</body>
</html>

Line 35 is:

if ($contents==$check) {

Am I executing a command incorrectly, is my connection too slow, or is my code just taking too long to execute?

Khishin 0 Newbie Poster

When using the Form1.KeyDown, keystrokes don't seem to register.

For example, the Click works fine:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        MsgBox("Hello")
    End Sub

That will display the message box when the form is clicked, but if you change it to:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        MsgBox("Hello")
    End Sub

I can't seem to get the message box to appear.

Khishin 0 Newbie Poster

How do you add controls through code instead of the form editor? I wasnt to do things like make a textbox appear when a button is pressed, but I'm looking for another way to do it than make a huge clutter of controls and edit the VISIBLE statement.

Something like:

Private Sub Button1_Click

delete button 3
create button 4

End Sub
Khishin 0 Newbie Poster

Adding to what cpopham said, make a subroutine for one of your buttons like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

objNewForm.ShowDialog()

End Sub

Also make sure you put Dim objNewForm as New Form somewhere near the top. It should be "as New Form" and not "as New NewForm()"

That's in my version at least.

Khishin 0 Newbie Poster

Sorry, I got it.

I was opening the form when I was already in VS.NET, and I was forgetting go go to View>Designer. I was using the text code editor.

Khishin 0 Newbie Poster

I'm using MS Visual Studio.NET, and when I try to open a project, nothing happens. I can open the Form1.vb or whatever I've named it to, but I can't see the graphic version of the form editor anymore. Do I have to load something else or is there a view option somewhere I missed?

Khishin 0 Newbie Poster

I downloaded QBASIC 4.5 onto a Windows XP computer, and placed it into C:\QBASIC\.

When I try to run QB.EXE though, I get the error:

C:\QBASIC\QB.EXE
Invalid startup directory, please check your pif file. Choose 'Close' to terminate the application.

What do I do here?

Khishin 0 Newbie Poster

How can I take only the high order bit from that command?

Khishin 0 Newbie Poster

Oh nevermind, you already know Java...

C++ is a good, powerful language that takes a lot of work, and Visual C++ would also be a good choice.

Khishin 0 Newbie Poster

I had realized that a bit after I posted, but I seem to be getting the low bit instead of the high bit, which is the one I need.

Isn't there a HIGH() operator or something?

Khishin 0 Newbie Poster

Here is the MSDN entry for the function:
GetKeyState()

Khishin 0 Newbie Poster

I don't know the function, but search for "define window" "resize window" and "split window"

Khishin 0 Newbie Poster

Also, next time you post code use code tags to make it easier to read.

Khishin 0 Newbie Poster

At the beginning of an "IF" statement, I have:

if (SHORT GetKeyState(int 48)==1){

When compiling I get a syntax error just before the constant, and I've played around with it a bit, but haven't found what to do.

Could someone fix this or explain to me why it's not working?

Khishin 0 Newbie Poster

They would miss the key they were aiming for, or feel like acting stupid. It's more for the sake of perfection, and I might learn something about how text characters are stored in integers, if at all.

Khishin 0 Newbie Poster

I have a PvP TicTacToe program running, and everything is working fine, except for one thing: when a text character (q,w,e,etc) is entered the loop goes wild.

Here's the portion of the code the loop is in, and if a text character is input instead of a digit, the loop keeps repeating without asking for another value.

cmove=0;
while (cmove!=1)
{

if (loop==1) cout<<"Player x's turn."<<endl;
if (loop==3) cout<<"Player x's turn."<<endl;
if (loop==5) cout<<"Player x's turn."<<endl;
if (loop==7) cout<<"Player x's turn."<<endl;
if (loop==9) cout<<"Player x's turn."<<endl;
if (loop==2) cout<<"Player o's turn."<<endl;
if (loop==4) cout<<"Player o's turn."<<endl;
if (loop==6) cout<<"Player o's turn."<<endl;
if (loop==8) cout<<"Player o's turn."<<endl;

cout<<"Which space do you wish to fill?"<<endl;
cin>>hmove;

cmove=3;
if (hmove==1) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==2) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==3) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==4) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==5) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==6) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==7) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==8) if (space [hmove]==0) cmove=1; else cmove=2;
if (hmove==9) if (space [hmove]==0) cmove=1; else cmove=2;

if (cmove==2) cout<<"That space is already taken."<<endl;
if (cmove==3) cout<<"That is not a valid space."<<endl;
cout<<endl;
}
cmove=0;

If it helps you understand what is going on, here is the full program:

#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main()
{

int space [9];
int hmove;
int fmove;
int cmove;
int loop;

while (1==1)
{
space [1]=0; …
Khishin 0 Newbie Poster

I won't write it in executable code, but this would be how to break out of the loop when 999 is entered.

while exit is not one{
   input number
   if number is not 999 sum=sum+number else exit=1
}

This way, at the end of the "while" loop, it would return to check if "exit" equals 1 or not. By default, it will equal 0, and will not change to 1 unless 999 is input.

Once "exit" equals 1 the code will go on. If you actually want 999 to be added to the sum, however, you could do this:

while exit is not one{
   input number
   if number is not 999 sum=sum+number else exit=1
   if exit=1 {
      output "Do you want to average the numbers now? (1=yes, 2=no)"
      input choice
      if choice=2 {sum=sum+999; exit=0}
   }
}

That way, if you enter 2, 999 will be added to the sum, and "exit" will be reverted to 0 before it is checked again.

Hope this helped.

Khishin 0 Newbie Poster

I have just started using C++ after a year or two of a BASIC language, and I wanted to do something that required some logic, but not a lot of different commands. I decided to do a tic tac toe playing program where your opponent was the program.

The way this is supposed to work is that the program goes through loops and put down pieces until the game ends, and keeping track of wins, losses, and draws in all of those possibilities, and find the best move based on the count. My question comes as pieces are put down, and after the sim-game has ended inside the counting cycle. I'm almost sure that if the spaces are not reset to empty before the next time it is used, it will interefere with the simulations. I was wondering when an where to reset the spaces.

My time on the computer is almost up for a while so I will post the start of my code and return tomorrow.

//simple AI for tic tac toe.

//load headers and namespace
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

//begin main function
int main()
{

int pos [9] ;
int turn ;
turn=9 ;
int space [9] ;
int wins [9] ;
int move [9] ;

/*

space positions

1 2 3
4 5 6
7 8 9

Winning possibilities
1 2 3
- - -
- - -

- - -
4 5 6
- - -

- …