Server Help

Non-Subspace Related Coding - tcsoccerman's General Questions

Mine GO BOOM - Sat May 05, 2007 1:40 am
Post subject: tcsoccerman's General Questions
Instead of jumping over two topics, condense into here.
tcsoccerman - Sat May 05, 2007 8:26 am
Post subject:
Lol, thanks MGB. how would you put a variable into text, something like this in C:

Code: Show/Hide

int nbr1;
printf("Enter a number:\n");
scanf("%d", &nbr1);
printf("you typed in %d", nbr1);

tcsoccerman - Sat May 05, 2007 8:39 am
Post subject:
Wow, so fustrating. I'll show you the method i declared:

Code: Show/Hide
void definitions(string english)
      {
         if (textbox.Text == "aprender")
         {
            labeldef.Text = "%s means %s";
         }
   }


and when i made a reference to it:

Code: Show/Hide
void ButtonClick(object sender, EventArgs e)
      {
         labeltitle.Text = textbox.Text;
         toolStripStatusLabel.Text = "Finding Definition...";
         definitions(to learn);
      }


and it gavbe me these errors:

Quote:
Invalid expression term ')'
; expected
) expected (CS1026)


and they all said in line 52, which is

Code: Show/Hide
definitions(to learn);


ty for any help.
_____________
btw, when i took that line out it compiled correctly icon_eek.gif icon_exclaim.gif icon_surprised.gif icon_eek.gif icon_rolleyes.gif
Samapico - Sat May 05, 2007 11:37 am
Post subject:
if 'to learn' is meant to be a string, you have to put it inside "quotes"
Code: Show/Hide
definitions("to learn");

and C# doesn't use any of these %s %i you were using with printf... it's actually much more intuitive than that...
Here's an example of using strings:

Code: Show/Hide

string GetDefinition(string word)
{
   if (word == "you")
      return "tu";
   else if (word == "bleh")
      return "bah";
   else
      return "unknown word";
}

void ButtonClick(object sender, EventArgs e)
{
    labeltitle.Text = textbox.Text;
    toolStripStatusLabel.Text = "Finding Definition...";
    int someInteger = 8;
    labelDefiniton.Text = "Definition of " + labelword.Text + " is " + GetDefinition(labelword.Text) + ", and the value of someInteger is " + someInteger.ToString();
}


Basically you just use '+' between parts of your string, and every litteral (string value that will not ever change during execution) must be "in quotes"
tcsoccerman - Sat May 05, 2007 11:51 am
Post subject:
Yep figured that out, but ty, that's exactly what i was asking. But since this is sorda gonna be a big database type thing, i was going to make a .cs file fora each type of word, for example, my first one will be for verbvs. i simply copyed and pasted, made the method a public method, but i get this error when i compiled:

Code: Show/Hide
Type or namespace definition, or end-of-file expected (CS1022)


it is referring to the last line of the file, where a "}" is underlined as the error. what does it mean?
Samapico - Sat May 05, 2007 12:10 pm
Post subject:
make sure there's a corresponding opening bracket for it... either an opening bracket is missing, either that last one shouldn't be there

you should have something like:

Code: Show/Hide
namespace blahblahblah
{
   class blahblah
   {
      void myMethod()
      {
      }

      void someOthterMethod()
      {
      }
   }

}

tcsoccerman - Sat May 05, 2007 12:12 pm
Post subject:
i'll check over that again. last question, then i'm leaving. what would i do to make it after they type in the word to be translated, when they press enter, it does the button clickevent. kinda like the google thing, just to make it easier to use.
Samapico - Sat May 05, 2007 2:54 pm
Post subject:
In the properties of your form, you will find 'AcceptButton' and 'CancelButton'. AcceptButton is the button to be pressed when you press Enter anywhere in the form, and CancelButton is the one for when you hit Escape
tcsoccerman - Sat May 05, 2007 3:44 pm
Post subject:
That's not in csharp dev, the one doc flabby suggested. it can wait though.
tcsoccerman - Tue May 08, 2007 5:53 pm
Post subject:
would it be possible to make a function, in a function that is being made, something like this:
Code: Show/Hide

void textchoose(int labelnbr)
{
   void definition(string spanish, string english, string verbending)
   {
   ....
....
   }
}


andthen reference to it like this:

Code: Show/Hide

textchoose(1);
textchoose(2);
textchoose(3);


the purpose is to ahve multiple textboxes to type into, and then you can type phrases in as well.
Cyan~Fire - Tue May 08, 2007 7:00 pm
Post subject:
No, that's not possible in C#, but explain a bit more what you're trying to do and there may be a better method.
tcsoccerman - Tue May 08, 2007 9:56 pm
Post subject:
I'm making a spanish translator, that will have 3 textboxes to enter a word into. there will be a button for each of those textboxes. then there will be a button that looks at all 3 words and translates the phrase vs. the sepreate words(spanish wording is different than english). i want to use the same function for each button so that when i edit one, i don't have to edit each other. i figured i must be specific in which textbox, and thought of the idea above. if this is not clear it's because i am in a hurry, and will answer any questions tom.
Doc Flabby - Wed May 09, 2007 4:43 am
Post subject:
You can do this, you just assign the same event to each button. But then use the "sender" object to obtain the correct result
tcsoccerman - Wed May 09, 2007 9:25 pm
Post subject:
Can you describe how i would do this. maybe add some sample code.
tcsoccerman - Thu May 10, 2007 9:19 pm
Post subject:
if i were to do this in C:

Code: Show/Hide

void definitions(int textboxnumber)
{
[u]   textbox[textboxnumber].Text = "test"
[/u]}

how wouldi do the underlined part, particarily the

Code: Show/Hide
textbox[[u]textboxnumber[/u].Text

part in c#?
tcsoccerman - Fri May 11, 2007 8:39 pm
Post subject:
Nobody is answering my questions, but anyways, i am moving along quite well w/ my program, and it's of course a spanish translator. First i'll describe how it works.
1.Type in a word.
2.Click the translate Button
3.Or Press Enter(although i'll describe this more later)
4.It shows the parameters of the definition function(not part of problem, describing vaguely).


Ever since i added the key press event, it reads the text to translate as you erase it. for example, if i entered

to learn

it shows up all the translation, and how to say it such as yo aprendo, tu aprendes, etc.
then when it turns to

to lear

(from backspacing). it shows my "else" coding(meaning, if it doesn't recgonize the word). thsi is a problem because my else coding says to make it say it wasn't found, and suggests help. this is 1. unproffesional like, and 2. makes my program much more incomplete. if you could think of a way of only recgonizing the <ENTER> key press, and not backspace/letters/any other button that would be great.
tcsoccerman - Sat May 19, 2007 4:30 pm
Post subject:
I'm working on a new project(a team tracking program) and i've gotten farther than i ever expected. i learned how to save txt and how to make new forms, and apply 1 forms user entered variables to the main form. anways, i'm having a problem b/w forms.

When you click the "new" button, it gives you a new form asking things such as the teamname, tream city, team coach, etc. when the user clicks ok, it collects all the txtbox.text in each category and sets that to a value. that value then becomes a labels text in the main applicatoin/mainform. the problem i'm having is closing the OLD mainfrom. i'll post my coding here.

My "new" event handler form too enter new info:
Code: Show/Hide
private void Button1Click(object sender, EventArgs e)
      {
         string teamname, teamcity, teamcoach, teamacoach1, teamacoach2, teamleague;
         teamname = txtboxcreateteamname.Text;
         teamcity = txtboxcreateteamcity.Text;
         teamcoach = txtboxcreateteamheadcoach.Text;
         teamacoach1 = txtboxcreateteamassistantcoach.Text;
         teamacoach2 = txtboxcreateteamassistantcoach2.Text;
         teamleague = txtboxcreateteamleague.Text;

         this.Close();
         MainForm frm = new MainForm(teamname, teamcity, teamcoach, teamacoach1, teamleague);
          frm.Show();
      }


and my mainform method:
Code: Show/Hide
      
      public MainForm(string tmname, string tmcity, string tmcoach, string tmacoach, string tmleague)
      {
         InitializeComponent();
         lblteamname.Text = tmcity+"  "+tmname+"\n"+tmcoach+tmacoach;
         lblawayrecord.Text = "0-0-0";
         lbloverallrecord.Text = "0-0-0";
         lblhomerecord.Text = "0-0-0";
         lblplayercount.Text = "0";
         
      }

any ideas appreciated.
this is c# code under "sharpdevelop" compiler.
Samapico - Mon May 21, 2007 12:55 pm
Post subject:
Code: Show/Hide
private void Button1Click(object sender, EventArgs e)
      {
         string teamname, teamcity, teamcoach, teamacoach1, teamacoach2, teamleague;
         teamname = txtboxcreateteamname.Text;
         teamcity = txtboxcreateteamcity.Text;
         teamcoach = txtboxcreateteamheadcoach.Text;
         teamacoach1 = txtboxcreateteamassistantcoach.Text;
         teamacoach2 = txtboxcreateteamassistantcoach2.Text;
         teamleague = txtboxcreateteamleague.Text;

         this.Close();
         MainForm frm = new MainForm(teamname, teamcity, teamcoach, teamacoach1, teamleague);
          frm.Show();
      }


You don't have to declare string variables for that... you could just pass the .Text values

And I'm not sure if Close() clears stuff from memory... I'd use .Dispose(), but after the new form is shown cause no code would be executed after the Dispose (I think)
In this case, it works because frm is not shown as a modal dialog
If you'd want the first window to stay, but be disabled, you'd use:
frm.ShowDialog(this);

Code: Show/Hide
private void Button1Click(object sender, EventArgs e)
      {
         MainForm frm = new MainForm(txtboxcreateteamname.Text,
                                                   txtboxcreateteamcity.Text,
                                                   txtboxcreateteamheadcoach.Text,
                                                   txtboxcreateteamassistantcoach.Text,
                                                   txtboxcreateteamleague.Text);
          frm.Show();
          this.Dispose();
      }

tcsoccerman - Mon May 21, 2007 3:31 pm
Post subject:
the only problem as i believe i stated b4 is that i'm trying to close another form, not the form that function is in. i have that "button1clickbuttonevent" in the form "addteam". i want to close the old "mainform", not "addteam".it's closing a form from another form.

also if you could answer other posts/questions i made that be greate too icon_smile.gif.
tcsoccerman - Tue May 22, 2007 3:40 pm
Post subject:
Ok, new problem, even though NOBODY RESPONDS. Lol, w.e., you don't have to. I'm trying to assign an integer to a label, and beable to retrieve that value at other times.

I want to do this to keep a record(wins-losses-ties). Everytime i call the function it retrieves the labels value and adds 1. I don't know how to do this w/ labels. i know i can do it w/other things, but they aren't what i need(updownlistboxthing is one way). Any help appreciated.
Animate Dreams - Thu May 24, 2007 8:29 pm
Post subject:
tcsoccerman wrote:
...NOBODY RESPONDS. Lol, w.e., you don't have to.


Lol, I'd help, but I don't know how. icon_sad.gif I just realized how much time I've been wasting this summer, too. Anyway, just think of it as helping the next guy who might have these problems.
tcsoccerman - Fri May 25, 2007 5:18 pm
Post subject:
could someone give an example of child/parent forms using...

MainForm()//mainform
AddTeam() //this is the child form


and there is a variable in AddTeam() (this is the child form)called "teamnametxtbox.Text" that i want to pass to the mainform(MainForm) and make it = "lblteamname.Text". That would be pimpin. Sampapico rocks. Oh, btw, i attached the program in topic "Team Tracker Program, version 1.0". I learned how to save . a biggie is not having a new form opening when the variables change, but just replacing the variables. I will attach the source and program here (it's slightly updated from the one in "leage manager" post). Thank you much.
Cyan~Fire - Sat May 26, 2007 11:17 am
Post subject:
I don't mean to be rude, but I'll say it how it is. Nobody is responding to you because you continue to ask very basic questions that could easily be worked around with a bit of ingenuity, looking at the API, and Google searching.
tcsoccerman - Fri Jun 08, 2007 5:50 pm
Post subject:
I'm pretty sure it's been long enough to ask another question now icon_smile.gif.

Does anyone have an idea/attempt on how i could incude players in my Team Tracker (TT) program? i thought of structures at first but i don't know if they are available in c#. ty.(again)
Cyan~Fire - Fri Jun 08, 2007 8:56 pm
Post subject:
Make a class, similarly to C++.

Code: Show/Hide
class Player
{
int foo;
int bar;
};


Then instantiate it with "Player p = new Player();".
tcsoccerman - Sat Jun 09, 2007 5:16 pm
Post subject:
Thank you for that cyan, but as i look farther into this problem, the more sloppy i see my solution. i then thought of another solution, of not looking to variables for a players name, goals, assists, age, etc., but instead look to a text file. that's how i do my teamdata right now. let me know if this would be a better solution. otherwise, i would have to make a struct/andor method and or class for every player. new_let_it_all_out.gif icon_eek.gif . ty for any suggestoins.
baseball43v3r - Sun Jun 10, 2007 2:40 am
Post subject:
it would be the same thing. it matters in how you call the data you want to use.

your hierarchy would be something like this.
Code: Show/Hide

                     PERSON
                  /      \   
               Player      Manager   
                 /      \         \   
               Forward      Goalie      Coach

and as you create the classes you create the fields specifc to each person and when you reference it you reference it by class. Hope this helps
tcsoccerman - Sun Jun 10, 2007 2:53 pm
Post subject:
Not really, you're arrows are messed up i think.... I've decided that's what i'll do though anyways. I'll start on it and let you know what i run into.
tcsoccerman - Sun Jun 10, 2007 4:27 pm
Post subject:
I'm getting a buggy error right now:
Code: Show/Hide
The process cannot access the file 'C:\Program Files\Team Tracker\ Logo' because it is being used by another process.

I realize what it means, but i can't seem to figure out the problem. This is happening when i change photos of either the team photo, or the player photo. I use the same variables for each form, since they are in different classes. that way i could copy+paste. Here is the team photo's "picdialogbox2ok" code:
Code: Show/Hide
void OpenpicDialog2FileOk(object sender, System.ComponentModel.CancelEventArgs e)
      {
         source = openpicDialog2.FileName;
         Stream openbmp =openpicDialog2.OpenFile();
         StreamReader openerbmp = new StreamReader(openbmp);
         openpicDialog2.Dispose();
         teamlogopicturebox.Image = new Bitmap(source);
         if (File.Exists(destination+lblteamname.Text+" Logo"))
         {
            File.Delete(destination+lblteamname.Text+" Logo");
         }
         System.IO.File.Copy(source, destination+lblteamname.Text+" Logo");
         photologo = destination+lblteamname.Text+" Logo";
         teamlogopicturebox.Image = new Bitmap(source);
}


and....the one for the player is the same, so i won't post that too. by the way, this is the only error i'm recieving. ty.
tcsoccerman - Sun Jun 10, 2007 4:32 pm
Post subject:
I have more info, i realize that when an actual file isn't opened, and i'm just randomly changing the photo, it works w/ out an error. Then, i open a file(which has a photopath in it's text) and change the files photo, and then get an error. hope this helps. it helps me....

I also found out it's the File.Delete part that is throwing the error.
Cyan~Fire - Tue Jun 12, 2007 9:20 pm
Post subject:
That's an awfully strange path, does the file even exist? If it does, you're probably opening it somewhere and not closing it.

This is the best way of closing a file when you're done with it, as the system will destroy the StreamReader right after the using block:
Code: Show/Hide
using (StreamReader foo = new StreamReader("file.txt"))
{
   string yayForLotsOfPointlessHeapAllocations = foo.ReadLine();
}


Another way of doing the same thing would be:
Code: Show/Hide
StreamReader foo = new StreamReader("file.txt");
string yayForLotsOfPointlessHeapAllocations = foo.ReadLine();
foo.Close();


but the first one is the recommended method.
tcsoccerman - Wed Jun 13, 2007 10:35 pm
Post subject:
Just so you know, i'm almost ready to release the new team tracker, but w/ players icon_smile.gif. If you want to speed up the process(most likely not) you could post a reply here telling me about arrays so i don't have to google. That would be sweet. Otherwise that's cool.
tcsoccerman - Wed Jun 20, 2007 9:20 pm
Post subject:
As i am coding more, i don't seem to enjoy having so much code on one page. therefore, i've tried adding a new page something like this:
the new file would have this:
Code: Show/Hide
namespace Team_Tracker
{
   public partial class MainForm : Form
   {
      public players()
      {
         InitializeComponent();
      }

      yadayadayada void money(blah, blah)
      {
      }
   }
}

and the one that has to much code/original would have this:
Code: Show/Hide
namespace Team_Tracker
{
   public partial class MainForm : Form
   {
      [STAThread]
      public static void Main(string[] args)
      {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new MainForm());
      }
      
      public MainForm()
      {
         InitializeComponent();
      }

      //lots of code
      //too much code
   }
}

would that be correct?
Cyan~Fire - Thu Jun 21, 2007 12:17 am
Post subject:
I don't really understand what you're trying to do. Can you clarify? (And fix the horrible tabbing in the first code block, please.)
tcsoccerman - Wed Aug 22, 2007 7:45 pm
Post subject:
hey there i'm back with this project now.
i've learned alot since the last time i tried. i'm now working on something that cyanfire suggested back on making a class:

class Player
{
int blah;
string foo;
};

i've run into one problem. i need to find a way to instintate the class, naming it by the players name. it will look something likethis:

Player <playernamehere> = new Player();

the problem is, i don't know how to "insert" the players name.
In c there is a snprintf() function, (commonly including the string buf) that can help with these sort of problems, or others like it. google searches didn't relate snprintf with c# icon_sad.gif. can anyone help me think of a way of inserting the players name?

EDIT:also i can't acces the file due to protection levels :\. I think i'm gonna just take the old approach to it.
Cyan~Fire - Thu Aug 23, 2007 12:40 am
Post subject:
Lookup C# constructors.
tcsoccerman - Tue Aug 28, 2007 7:14 pm
Post subject:
i did as you said and that really isn't what i wanted, but it was helpful in other ways. basically i'll give it straight out.

instead of having to do

player Bob = new player();

or

player hannah = new player();

or some other SET name, i want to do something like this:

player txtboxname.Text = new player();

excepty you can't do that, becasue "txtboxname.Text" gives an error. how can i do this correctly?
tcsoccerman - Tue Aug 28, 2007 7:42 pm
Post subject:
ok i've found my answer finally, by searching keyword "objects" at msdn
here's the coding.

Code: Show/Hide
System.Windows.Forms.TreeNode lb;
   if(team1players.Focused == true)
   lb = team1players.SelectedNode;
   else
   lb = team2players.SelectedNode;
   object name;
   name = lb.Name;
   name = new player();


i'm glad to say i found a reason for object oriented programming finally! icon_smile.gif.
Cyan~Fire - Wed Aug 29, 2007 1:15 pm
Post subject:
OK, I really have to ask this. Did you really do any kind of C# tutorial before you started this stuff? It seems to me like you are copy+pasting and modifying code without any kind of understanding of what it actually does...
tcsoccerman - Wed Aug 29, 2007 10:51 pm
Post subject:
you're half right half wrong.

i took no tutorial.
i learned c programming before c# though, so i have the basics(or do i) down. i do understand what i'm doing for the most part, it's just my c# dictionary is very small. here's how it works for me

code
find problem
google problem
google
google
google
ask this topic
solved

ty for answering though. and if you're wondering, i do realize that the above post is wrong, and missing some code. i got that code though. ty for you're help so far.
Cyan~Fire - Wed Aug 29, 2007 11:41 pm
Post subject:
Do a tutorial. Your questions have indicated a lack of basic understanding of the language and it would be good for you to sort of start over, sorry to say it. icon_confused.gif
tcsoccerman - Wed Aug 29, 2007 11:52 pm
Post subject:
ok i will do a tutorial, but one quick question. how can you access already existant created instances of classes without using the "new" operator?
CypherJF - Thu Aug 30, 2007 7:12 am
Post subject:
You create a instance of a object when you use the 'new' operator.

You'll need to keep the object reference around to use elsewhere.
tcsoccerman - Thu Aug 30, 2007 10:52 am
Post subject:
ok thank you.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group