C# Help

Started by G_G, September 15, 2009, 12:18:13 am

Previous topic - Next topic

G_G

September 15, 2009, 12:18:13 am Last Edit: September 15, 2009, 11:47:32 pm by game_guy
Okay well I decided to remake the browser in C# I'm liking it already. Anyways I need some help. So here's the questions.


Question 1
Okay so I want to be able to have bookmarks. So you can add things to a menu strip by doing this.

menuStrip1.Items.Add("Fruit");


Okay so here's my idea, I wanted to save all bookmarks in a file which I figured out how to do. Now my question is pretty much like the one with visual basic. So this is what I want to do.

# below is the text containing all bookmarks just for example
text = [bookm1, bookm2, bookm3]
# okay so thats three bookmarks
for i in 0...text.size
  menuStrip1.Items.Add(i.tostring);
end


If that made any sense at all...Anyways I want it like that if anyone can help please that'd be great.


Question 2

Okay when my browser is done I'm going to make a help file for it. So this is kind of two questions.
How would I open this helpfile? I have a top tool bar that has a Help button on it so I want that to open the help file.
Next how would I just open this helpfile by pressing F1 or something?


Question 3

Next okay so how would I go replacing all the spaces in a line of text? Like the url says this

you tube.com

How would I replace that space with nothing or with a different letter/symbol? Something like this in ruby.

name = "Alu x es"
name.delete!(" ")

that would delete all the spaces but not only do I want to do that I want to be able to replace that space with a letter or symbol. Is is possible and if so how?

winkio

Not really familiar with visual basic, but an ITERATOR is what you need.  Find one, make one, use one.

fugibo

Quote from: game_guy on September 15, 2009, 12:18:13 am
Okay so how would I only get text from the 3rd line? I know how to get the whole text file but I would only like to get the 3rd text line. Is it possible if so how?

I'll have more questions up here as soon as I can manage to fit them into understandable questions -_-


Doesn't .NET have Regular Expressions?

Blizzard

I don't think there is a serious programming language that does not have regex.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on September 15, 2009, 10:05:00 am
I don't think there is a serious programming language that does not have regex.


C.

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

scoace13

you could try reading the file in a loop and writing each line to a variable and then clear the other two...thats generally how i read specific lines. in vb....i cant get you the code for such a thing cause it's been two + years since my last VB class and i don't remember every thing too well.
scoace13, Eventman extrodnaire...so anybody seen any good movies recently <br />...whys is this here..........random fate...same reason im here...

Blizzard

So what you want is basically reading a file where every line that starts with # is treated as comment and should be skipped?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

yea that and there will be more lines then that to

I'll try to google some more

fugibo

Quote from: game_guy on September 15, 2009, 06:11:31 pm
yea that and there will be more lines then that to

I'll try to google some more


You should really be using C++, there's no reason to limit yourself with VB. In C++, this would be simple.

G_G

yea I know more visual basic then c++ and the only things I do know in c++ is the command prompt thing

fugibo

Quote from: game_guy on September 15, 2009, 06:54:07 pm
yea I know more visual basic then c++ and the only things I do know in c++ is the command prompt thing


Well then, IronRuby.

G_G

September 15, 2009, 07:14:02 pm #12 Last Edit: September 15, 2009, 07:22:42 pm by game_guy
so is that using ruby in visual basic or c++?

EDIT:
Does anyone know how you could do this in C#?

fugibo

Quote from: game_guy on September 15, 2009, 07:14:02 pm
so is that using ruby in visual basic or c++?


You know what .NET is, right? It's built on top of the Common Language Runtime, or CLR - a sort of engine that allows for you to use any languages you want together on top of .NET. IronRuby is a port of Ruby to the CLR, meaning you can use it together when any other .NET language you want, as well as use .NET itself. All from within the language you probably know best, Ruby.

G_G

OKay so where would I edit the code then? In a ruby compiler, visual basic, or what? I'm still confused a bit.

Thanks tho LF for helpinh

jcsnider

If you are using Vb.. make a module and add a GETvar and Putvar sub, so that you cna read/write to ini files, then make the text file an ini file... which is alot better and in windows it is classified as a cfg file... it has been awhile since I have done it but it would work for what you want...

G_G

September 15, 2009, 07:55:31 pm #16 Last Edit: September 15, 2009, 07:59:10 pm by game_guy
I know how to read from a .ini file but how do I write to it?

Here's the read code.
Dim ini As New IniFile(FileName)
Dim value As String = ini.GetString("SectionName", "KeyName", "Default Value")


Well and I have a class that has that. But I dont understand how to write to it

jcsnider

Probably same thing but ini.Putstring

Not sure, I always go featch code from google and it tells me how to use it, i never really remember it either

fugibo

Quote from: game_guy on September 15, 2009, 07:24:05 pm
OKay so where would I edit the code then? In a ruby compiler, visual basic, or what? I'm still confused a bit.

Thanks tho LF for helpinh


Like I said, it's just programming for .NET in Ruby. You use VS and everything - exactly the same as with Visual Basic, but with Ruby.

G_G

Okay I changed the topic and added three new questions so if someone could help I'd like that

winkio

September 16, 2009, 01:05:14 am #20 Last Edit: September 16, 2009, 01:09:41 am by winkio
Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 1
Okay so I want to be able to have bookmarks. So you can add things to a menu strip by doing this.

menuStrip1.Items.Add("Fruit");


Okay so here's my idea, I wanted to save all bookmarks in a file which I figured out how to do. Now my question is pretty much like the one with visual basic. So this is what I want to do.

# below is the text containing all bookmarks just for example
text = [bookm1, bookm2, bookm3]
# okay so thats three bookmarks
for i in 0...text.size
 menuStrip1.Items.Add(i.tostring);
end


If that made any sense at all...Anyways I want it like that if anyone can help please that'd be great.

a few points:
use // instead of # for comments
C# uses real arrays, not the floating amorphic stuff of RGSS.  Learn how they work, or else you are screwed.
semicolons
for loops
braces { } instead of ends

// below is the text containing all bookmarks just for example
string[] text = {"bookm1", "bookm2", "bookm3"};
// okay so thats three bookmarks
for (int i = 0; i < text.Length; i++)
{
    menuStrip1.Items.Add(text[i]);
}

(for all those coders out there, I know I could have used an extended for loop, but I think he should know the regular ones first.)
Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 2
Okay when my browser is done I'm going to make a help file for it. So this is kind of two questions.
How would I open this helpfile? I have a top tool bar that has a Help button on it so I want that to open the help file.
Next how would I just open this helpfile by pressing F1 or something?

you are going to need to add a keyboard event listener, then make an onKeyboardEvent method.  But you have no idea how interfaces and stuff work, so good luck.  I'd ask when you get there.

Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 3

Next okay so how would I go replacing all the spaces in a line of text? Like the url says this

you tube.com

How would I replace that space with nothing or with a different letter/symbol? Something like this in ruby.

name = "Alu x es"
name.delete!(" ")

that would delete all the spaces but not only do I want to do that I want to be able to replace that space with a letter or symbol. Is is possible and if so how?

There is an easier way with regex, but I don't know if you will be ready for it, so I'll give you a method that splits and recombines:
string s = "Al u xes";
           // replace the ' ' with whatever character to split at.  It's an array, so you can split at any number of characters.
           char[] delim = { ' ' };
           string[] ssplit = s.Split(delim);
           string snew = ssplit[0];
           for (int i = 1; i < ssplit.Length; i++)
           {
              //replace the '-' with whatever you want to replace the space
               snew += "-";
               snew += ssplit[i];
           }

at the end, snew has the new string, which in this case, is Al-u-xes.

Blizzard

September 16, 2009, 05:30:06 am #21 Last Edit: September 16, 2009, 05:38:05 am by Blizzard
1. Let's say you have an array or list of strings.

foreach (string bookmark in array)
{
   menuStrip1.Items.Add(bookmark);
}


Or winkio's alternative using an index iterator. Or even this:

menuStrip1.Items.AddRange(array);


2. If I remember right, you can embed a chm file which you generated beforehand using HMTL Workshop or some other HTML compiler. Look it up on the internet, it's very easy.
If you add the help file call to an option in the menu strip, you can bind F1 as hotkey over the "Properties" window. Then simply double click on the option in the menu to generate a click event in which you put in the code to call the help file.

3.
string = string.Replace(" ", ""); // replaces spaces with empty strings
string = string.Replace(" ", "-"); // replaces spaces with dashes


I'm not 100% sure if it was "Replace" or some other method, but you shouldn't have no problems finding the right one with Intellisense.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

right, Blizz has experience, while I picked up C# 2 weeks ago.  :^_^':

G_G

thanks guys for your help :) *lvs up*

Blizzard

Oh, don't worry about it, winkio. :) You'll learn quickly how fast you can do some things in C#. It didn't take me long to learn some of the nice features the object model of .NET supports. :D

We made an embedded help file in a college course so I still kinda remember how we did it. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

yeah for the intro to computer game creation course, we are building our final project in C# using XNA libraries (thus why our textbook is an xbox 360 controller :P)

I don't think I've ever touched .NET...

Blizzard

One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

@#3: You'll want to use a Regex to replace spaces after the original domain with %20 and just delete the rest.

G_G

September 16, 2009, 06:48:22 pm #28 Last Edit: September 16, 2009, 06:56:21 pm by game_guy
okay another question...well problem when I click a link that normally opens a new tab or window it opens up internet explorer instead and same thing with downloads...anyway to fix this?

EDIT:
How do we open another form up?

Blizzard

Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: Blizzard on September 17, 2009, 02:14:03 am
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.


Its apparently an error when I use the
childForm.MdiParent = this;

It wont work this is the error
Form that was specified to be the MdiParent for this form is not an MdiContainer.
Parameter name: value


This is my code
Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();

fugibo

Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.

Blizzard

Quote from: game_guy on September 25, 2009, 08:30:59 pm
Quote from: Blizzard on September 17, 2009, 02:14:03 am
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.


Its apparently an error when I use the
childForm.MdiParent = this;

It wont work this is the error
Form that was specified to be the MdiParent for this form is not an MdiContainer.
Parameter name: value


This is my code
Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();



The parent window probably isn't an MDI container. :P Either leave that line out or make the parent window an MDI container. It should be one of the window properties.

Quote from: Longfellow on September 26, 2009, 08:56:08 am
Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.


Don't be affected by your Max bias. It's not as slow as you think.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

I tried that and it worked. But it displayed the window behind everything in the parent window.. The background of the first form was grey when I changed it, then I tested it and form2 displayed in the grey but behind everything else

Also say I want to create a module method like this.
module Config
  def self.write_text(file, text)
    # stuff here
  end
end


I want to create a method in a seperate thing where I can just call it like this
Text.write_text("Test.txt", "Test")


So exactly what do I do to go doing that? I know its not going to be the same as rgss but I'm trying to explain it in rgss is all.

Blizzard

You should probably use the intended MDI container "class" then. xD

There are classes and methods for file access like File and File.Open. Just use the Intellisense. It will guide you through what you need to use. Just read what the methods and parameters do.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Well I know how to do the file open and stuff but I want a method that I can just call that writes text to the file so I dont have to keep typing the same thing over and over. If I have to I will.

Blizzard

FileStream.write(STRING)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

September 27, 2009, 03:46:08 pm #37 Last Edit: September 27, 2009, 03:47:26 pm by Longfellow
Quote from: Blizzard on September 27, 2009, 01:53:17 pm
Quote from: Longfellow on September 26, 2009, 08:56:08 am
Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.


Don't be affected by your Max bias. It's not as slow as you think.


For the record, Objective-C isn't "fast" either - it's almost as dynamic as Ruby, which means it's also much slower than C/C++. My main complaint with C# is that on Windows, there's no need for a VM, so that's just slowing it down and sucking battery life for no reason, and on other platforms like Zune/WinMobile, a VM is just overkill (my only complaint with Android is that it uses a VM, too). This isn't Java, where you're compiling for every platform you can, this is (for all intents and purposes) a Microsoft-only product with all the limitations of a cross-platform product. If C# took the Obj-C route and just ran off a dynamic runtime, it'd be awesome, but right now it's ridiculous.

(Edit: This is pretty ironic, given that it's coming from a guy who considered writing an IDE in pure Ruby a year ago :P)

Blizzard

I agree, C# VM just for Windows isn't needed. But C# wasn't supposed to be Windows only. It's just that Unix users don't want to have a good and versatile language such as C# for Unix because of their childish and usually just Unix-fanboy based hatred for Microsoft. Mono never went beyond .NET 1.0 which is quite a shame especially since .NET 2.0 is MUCH better than 1.0. Blame the fanboys, it's their fault.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on September 27, 2009, 03:51:40 pm
I agree, C# VM just for Windows isn't needed. But C# wasn't supposed to be Windows only. It's just that Unix users don't want to have a good and versatile language such as C# for Unix because of their childish and usually just Unix-fanboy based hatred for Microsoft. Mono never went beyond .NET 1.0 which is quite a shame especially since .NET 2.0 is MUCH better than 1.0. Blame the fanboys, it's their fault.


Uh, Mono is still under development, and I'm pretty sure it's nearly 2.0 if it's not already. 0_o A lot of people are using it, too - it's just that a lot still prefer Gtk/Python or Qt, and don't really have any need for Mono yet.

And then there's the fact that they're always gonna be two steps behind Microsoft, simply because it's an Open Source project following a closed-source, proprietary project.

Blizzard

STILL under development? O_o Geez, one would expect that they finally made some progress. But at least they are still working on it.

Yeah, that's true with the open source-closed source problem. MS did release .NET 1.0 as open standard, but they never did it for 2.0 or later so it's understandable why there are problems. But at least they have an interface they can implement even though the inner implementation might not be that good. (Maybe I should join the Mono dev team O_o)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on September 28, 2009, 04:48:39 am
STILL under development? O_o Geez, one would expect that they finally made some progress. But at least they are still working on it.

Yeah, that's true with the open source-closed source problem. MS did release .NET 1.0 as open standard, but they never did it for 2.0 or later so it's understandable why there are problems. But at least they have an interface they can implement even though the inner implementation might not be that good. (Maybe I should join the Mono dev team O_o)


You've got a slight misunderstanding about OSS - it's not really "done" until it implements every feature it can as stable and fast as it can on every platform it can. In other words, it's constantly "under development," which doesn't mean that no progress has been made, just that "not everything is finished yet."

Blizzard

No, I got it wrong before that. I thought that they weren't doing anything before my post. As I said, at least they get something done even if the progress is quite slow.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

October 04, 2009, 11:59:52 pm #43 Last Edit: October 05, 2009, 12:26:14 am by game_guy
Okay I had a cool idea, now I got it to work for the most part. You all know I'm making a browser so this is what I decided I'll be releasing updates for it alot so I made an updater. The farthest I got was it actually downloading but I cant get it to extract the zip

Anyhelp on extracting a zip file?

EDIT:
Okay well remembering google is my friend I googled it and figured it out. So now when my web browser is released it'll come with am automatic updater. :D AWESOMNESS!!

fugibo

Quote from: game_guy on October 04, 2009, 11:59:52 pm
Okay I had a cool idea, now I got it to work for the most part. You all know I'm making a browser so this is what I decided I'll be releasing updates for it alot so I made an updater. The farthest I got was it actually downloading but I cant get it to extract the zip

Anyhelp on extracting a zip file?

EDIT:
Okay well remembering google is my friend I googled it and figured it out. So now when my web browser is released it'll come with am automatic updater. :D AWESOMNESS!!


Too bad that that functionality breaks the instant you change webhosts.

Blizzard

I wonder how www.chaos-project.com was able to always remain the same regardless who the actual webhost was. Hm, hm. What a big mystery that is. And I wonder even more what URLs are good for.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

October 05, 2009, 02:59:03 pm #46 Last Edit: October 05, 2009, 05:23:38 pm by game_guy
hmmm hmm so many questions hmm hmm
@lf: I used a url and it works perfectly. Downloads it, then extracts the zip file, then closes the browser so updates can take place.

EDIT:
Okay just a question..so I have my file on my host, now how would I like make it go to another host to get the file, if the firsthost is down? Here's my code.

WebClient download = new WebClient();
byte[] filedata = download.DownloadData("first host here");
FileStream file = File.Create(Application.StartupPath + "\\update.zip");
file.Write(filedata, 0, filedata.Length);
file.close();


Now last night my host was down so it couldnt download the file, so I want it to be able to go to another host if it cant access the first. Is it possible? if so how?

Ryex

October 06, 2009, 02:16:22 am #47 Last Edit: October 06, 2009, 02:17:26 am by Ryexander
so I'm building a RMX-OS GUI (just as kind of a learning exsperience)

here's the code
Spoiler: ShowHide

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
   public partial class RMX_OS_GUI : Form
   {
       string filePath = "";
       public RMX_OS_GUI()
       {
           InitializeComponent();
       }

       private void spathbutton_Click(object sender, EventArgs e)
       {
           
           openFileDialog.Title = "Server File Location";
           if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               filePath = openFileDialog.FileName;
               spathstb.Text = filePath;
           }
       }

       private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
       {

       }

       private void spathstb_TextChanged(object sender, EventArgs e)
       {
           filePath = spathstb.Text;
       }

       private void run_server_button_Click(object sender, EventArgs e)
       {
           if (filePath != "")
           {
               RmxosProcess.EnableRaisingEvents = true;
               RmxosProcess.StartInfo.FileName = filePath;
               RmxosProcess.Start();

           }
       }

   }
}



browsing for the file path and saving it to filePath works fine it's when i press the run button

this code is exacuted

private void run_server_button_Click(object sender, EventArgs e)
       {
           if (filePath != "")
           {
               RmxosProcess.EnableRaisingEvents = true;
               RmxosProcess.StartInfo.FileName = filePath;
               RmxosProcess.Start();

           }
       }

the problem is that the ruby prompt just flashes up or a fraction of a second and disappears (closes as if the file didn't have any puts commands)
is there a way to get it to really run the server?

and yes I've learned all that in a few hours for those who were wondering
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Try adding "ruby " before the filepath.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

nope I even tried this

private void run_server_button_Click(object sender, EventArgs e)
        {
            if (filePath != "")
            {
                RmxosProcess.EnableRaisingEvents = true;
                RmxosProcess.StartInfo.Arguments = filePath;
                RmxosProcess.StartInfo.WorkingDirectory = "C:\ruby\bin";
                RmxosProcess.StartInfo.FileName = "ruby.exe";
                RmxosProcess.Start();

            }
        }


started the ruby.exe and then passed the file name as a parameter
same effect

also if you type
C:\ruby\bin\ruby.exe C:\Users\Ben\Desktop\Remexos Server\RMX-OS.rb
into the windows run prompt the same thing happens... strange
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Are you sure that RMX-OS is running normally on your PC?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Ryex here's what you could do.
private void launchserver_Click(object sender, System.EventArgs e){
System.Diagnostics.Process.Start(Application.StartupPath + "\\RMX-OS.rb");
}

That'll run the rb script, as long as the rmx-os thing is in the same folder as the application.
I tested it and it should just run it right away.

Ryex

lol one when the window opened and closed i saw a glips of text so using my considerable screen capture skills i was able to read it it wasn't my program at all but for some reason calling it that way in c# means it is unable to find the cfg.ini file so it closes! now to figure out how to fix that...
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

October 06, 2009, 06:13:50 pm #53 Last Edit: October 06, 2009, 07:39:43 pm by game_guy
hmm wierd because it ran for me I dunno I'll look into it a bit more

EDIT:

The program is in the same folder as the script right? and the cfg.ini and everything else?

Ryex

October 06, 2009, 08:00:21 pm #54 Last Edit: October 06, 2009, 08:23:54 pm by Ryexander
I haven't tried your code yet so i'll see if it works

EDIT: your code dose work G_G

also dose any one know how to check if a process is running?
ie if the ruby.exe file is running or the RMX-OS.rb file is open some where the latter preferably
I also need to know how to test if a file exists like Filetest.exist? in ruby
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

MessageBox.Show("", "", MessageBoxButtons.YesNo);


That brings up a message box with buttons that have Yes and No.
How do I check to see which button was pressed?

Ryex

ok I now know how to file test and apparently testing for if the RMX-OS.rb file is open won't work
at least not with this code

try
            {

                FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write,
                FileShare.None);
                fs.Close();
                serverRunState = false;
                serverRunStateLabel.Text = "Not Running";
                serverRunStateLabel.ForeColor = Color.Red;
                serverRunTested = true;
            }
            catch (FileNotFoundException)
            {
                //what to do now?
                serverRunState = false;
                serverFileState = false;
                serverFileStateLabel.Text = "Not Found";
                serverRunStateLabel.Text = "Not Running";
                serverRunStateLabel.ForeColor = Color.Red;
                serverFileStateLabel.ForeColor = Color.Red;
                serverRunTested = true;
            }
            catch (UnauthorizedAccessException)
            {
                serverRunState = true;
                serverRunStateLabel.Text = "Running";
                serverRunStateLabel.ForeColor = Color.Green;
                serverRunTested = true;
            }
            serverRunTested = true;

I think i might just give up on that one
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

If you needed to see if it was already running do this.
First add this at top
using System.Diagnostics;

then where it says name, place the process

public bool IsProcessOpen(string name)
{
                if (clsProcess.ProcessName.Contains(name))
                {
                        return true;
                }
        }
        return false;
}

Ryex

yes but i can only test for ruby.exe not the RMX-OS.rb, and the ruby.exe could be running and number of ruby programs not the the RMX-OS server
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G


Boolean running = true;
private void launchserver_Click(object sender, System.EventArgs e){
System.Diagnostics.Process.Start(Application.StartupPath + "\\RMX-OS.rb");
}
public bool IsProcessOpen(string name)
{
               if (clsProcess.ProcessName.Contains(name))
               {
                       if (boolean == true)
                       {
                           return true;
                        }
               }
       }
       running = false;
       return false;
}

K hang on I'm going to try and put something together real fast

Ryex

October 07, 2009, 12:09:47 am #60 Last Edit: October 07, 2009, 01:03:52 am by Ryexander
I just got a brilliant idea! if you run two servers at the same time through the same port you get an error because only one use of the port is normally permitted could this be used to test if the server was running?

EDIT so I looked around and it would be something like this right?

            IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
            try
            {
                TcpListener tcpListener = new TcpListener(ipAddress, <portnumber the server is useing>);
                tcpListener.Start();
            }
            catch (SocketException ex)
            {
                MessageBox.Show(ex.Message, "kaboom");
            }


the Exception would throw if the server was already running right?

the only problem is how do I get access to those functions? I need to be using a specific name space but which one?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

What you are doing there is pretty much implementing a C# version of RMX-OS. You don't need to do that.

@G_G: Message.Show freezes the execution until the users closes the dialog. It returns a DialogResult instance which you can compare to DialogResult.XXXX constants to check which button was pressed. I used the same thing in Blizz-ABS Config.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Quote from: Blizzard on October 07, 2009, 05:43:32 am
What you are doing there is pretty much implementing a C# version of RMX-OS. You don't need to do that.

@G_G: Message.Show freezes the execution until the users closes the dialog. It returns a DialogResult instance which you can compare to DialogResult.XXXX constants to check which button was pressed. I used the same thing in Blizz-ABS Config.


C# version of RMX-OS? no I'm just building a GUI for it, and i don't want the run button to work if there is already a server copy running or there is something already using the port that RMX-OS is configured to use. the GUI will have other stuff too. like a tab for easy configuration of RMX-OX and quick viewing of the log files. I also plan to have the ability to register a new user with the option to make said user a admin. other stuff too.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Hm... I think that it's possible to check if a process is still running if you keep a reference at it. So when you run the ruby process with RMX-OS, you could use an additional thread to check if the process is still alive.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay just a question..so I have my file on my host, now how would I like make it go to another host to get the file, if the firsthost is down? Here's my code.

WebClient download = new WebClient();
byte[] filedata = download.DownloadData("first host here");
FileStream file = File.Create(Application.StartupPath + "\\update.zip");
file.Write(filedata, 0, filedata.Length);
file.close();


Now last night my host was down so it couldnt download the file, so I want it to be able to go to another host if it cant access the first. Is it possible? if so how?

Ryex

ga I'm trying to load all the options from the RMX-OS cfg.ini file
I'm storing the entire file to a string and then going through with regexp to find "Keyword = value" matches storing the value according how ever since some of the values are things like 'Localhost' with the single quotes or "Localhost" with double quotes I need to remove the '' or "" if it has them
but so far I have been unsuccessful in creating a working regexp to match something surrounded by quotes can some one help me?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Can you get back at me with that later? My brain is unusable today. I'll put a regex together that will parse the file properly for you.

Or you can try to use the integrated "read ini" methods.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Quote from: Blizzard on October 08, 2009, 03:46:04 am
Can you get back at me with that later? My brain is unusable today. I'll put a regex together that will parse the file properly for you.

Or you can try to use the integrated "read ini" methods.

I could... if the file was in proper ini format. right now its formatted like a ruby script and RMX-OS loads it like one.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

October 08, 2009, 01:11:13 pm #68 Last Edit: October 08, 2009, 02:06:34 pm by Blizzard
Well... Except for sections and having spaces between the key, the = sign and the value, it's pretty much the same.

EDIT:

Run this regex for strings.

"(\S+?) = \"(.*)\""


Then run this regex for more strings:

"(\S+?) = '(.*)'"


This one for boolean:

"(\S+) = (true|false)"


Floats:

"(\S+) = (\d+\.\d+)"


And integers:

"(\S+) = (\d+)[^\.]"


I put all regexes in " quotes and escaped the " quote character within. I didn't use regex with C# so far so I'm not sure if you use a string for it or if there is an integrated regex class (i.e. /(\S+) = (\d+\.\d+)/)

You will have to do some afterprocessing for the extensions though:

"(\S+?) = \[((?:.|\n)*)\]"


This will give a string with \n , ' and " characters which you will have to filter.

And keep in mind that this doesn't support comments with " and ' characters. In fact, comments should be avoided in the ini file.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

How do I execute a code from a textbox or something? Like in rmxp you can do this
eval(code)

How would we do that in C#?

fugibo

Quote from: game_guy on October 08, 2009, 03:40:48 pm
How do I execute a code from a textbox or something? Like in rmxp you can do this
eval(code)

How would we do that in C#?


You can't. Go read up on "interpreters" and "machine code." You'd have to compile the code against your current code base, then execute it, which might be impossible.

Blizzard

October 08, 2009, 07:10:23 pm #71 Last Edit: October 08, 2009, 07:12:24 pm by Blizzard
Bullshit. http://www.codeproject.com/KB/cs/evalcscode.aspx Where's your god now?

Also, I remember that C# 4.0 was supposed to have an Eval function support natively, but I can't find it anywhere in the specs.

BTW, eval is usually bad practice. Don't use unless you'd end up with a billion switch case statements.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on October 08, 2009, 07:10:23 pm
Bullshit. http://www.codeproject.com/KB/cs/evalcscode.aspx Where's your god now?

Also, I remember that C# 4.0 was supposed to have an Eval function support natively, but I can't find it anywhere in the specs.

BTW, eval is usually bad practice. Don't use unless you'd end up with a billion switch case statements.


Crap. I knew someone would probably have done this anyway, but *blah.* So how does that work, recompiles the code?

G_G

October 08, 2009, 10:42:01 pm #73 Last Edit: October 09, 2009, 01:01:24 am by game_guy
I googled how to setup a tooltip and I just ran into confusing constructions, can anyone help me how to setup a tooltip?

EDIT: Dont worry about the tooltip I figured it out. But I want to figure out how to get every item from a combo box.
I figured out how to get the amount of items in it by using this.
comboBox1.Items.Count;

What I want to do is be able to like get every item in there. Like how would I do the for i in 0...size command in c#?

Blizzard

October 09, 2009, 03:40:13 am #74 Last Edit: October 09, 2009, 03:41:39 am by Blizzard
Quote from: Longfellow on October 08, 2009, 07:27:37 pm
Crap. I knew someone would probably have done this anyway, but *blah.* So how does that work, recompiles the code?


Compilation on the fly from what I can see from the code. IMO it's a stupid idea to force eval. One should be very, very careful when using it. :/

Quote from: game_guy on October 08, 2009, 10:42:01 pm
I googled how to setup a tooltip and I just ran into confusing constructions, can anyone help me how to setup a tooltip?

EDIT: Dont worry about the tooltip I figured it out. But I want to figure out how to get every item from a combo box.
I figured out how to get the amount of items in it by using this.
comboBox1.Items.Count;

What I want to do is be able to like get every item in there. Like how would I do the for i in 0...size command in c#?


It implements IEnumerable, just iterate through it.

foreach (object item in comboBox.Items)
{
}


Just don't forget to cast the objects. I hope you didn't put in objects of different classes. BTW, did you know that if you put in objects and override ToString() in the definitions of those objects, you can have code that is easier to read and more organized? The combobox calls ToString() to display the items.

class Person
{
   public string name = "Johnny";
   public override string ToString()
   {
       return this.name; // displays this item as "Johnny" in a combobox/listbox
   }
}


Syntax might have errors, I haven't written C# code for some while.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay one more thing the item in the iterate is pretty much the x variable then right?

Blizzard

Yeah, it's the equivalent of this Ruby code:

for item in combobox.Items
end
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay works perfectly thanks blizz one more thing is it possible to do it with a text file except this time with lines?
for line in text.lines?

Blizzard

For strings you can use this:

foreach(string line in text.Split("\r\n"))
{
}


If "\r\n" doesn't work for you, use just "\n".
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

thanks blizz I've been able to load and save the configuration successfully thanks to you.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

Okay I'm making a dll in c# and the farthest I got was actually creating the class library.
I really dont know where to start so can anyone help me?

G_G

Dont worry about above question, I've figured out where to start.

anyways I'm having troubles. So I have an array that has Strings in it.
Now I also have a combobox and a method thats supposed to add every string thats
in the array into the combobox.
Anyone help me please?

Blizzard

combobox.Items.AddRange(stringArray);
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

hey blizzard any idea why a 2.0 C# project would fail to load the mscorlib.dll on a windows 2000 computer with .net 2.0 installed?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Maybe they changed that dll. I'm not sure .NET works on Windows versions before XP.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

hmm well the DL pages say 2000 is supported but almost nothing further back
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

IDK then. Try googling.
BTW, you can now post separate threads. :P
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: Blizzard on October 12, 2009, 05:30:43 am
combobox.Items.AddRange(stringArray);


K it worked but I just found out that wasnt the problem -_-
see this string array loads everyline from a text file and I dont think
I'm doing it right.


Blizzard

It may be best if you just find the method in FileStream that returns an array of strings that represent the lines in the text file.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

October 12, 2009, 02:50:19 pm #89 Last Edit: October 12, 2009, 02:56:40 pm by Ryexander

using System.Text.RegularExpressions;
string[] stringarray = Regex.Split(textstring, "\r\n");

that will create an array of strings if textstring is the entire text of a file with each string you want on a new line
or this is how i loaded the exstention names form the RMX-OS config file into an array


string[] EXTENSIONS = new string[] {""};
EXTENSIONS[extension_int] = namestring;
extension_int += 1;

and I started the extension_int at 0
useing this you just read each line of the file to a string load it in to the array at the extension_int index and then increase extension_int by 1 to move the next spot in the array for the next string.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

I don't think you need Regex for this. string supports the Split() method.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

oh good point
string[] stringarray = string.Split("\r\n") would do the same wouldn't it...
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

October 12, 2009, 03:06:00 pm #92 Last Edit: October 14, 2009, 04:55:23 am by Blizzard
Yeah, that should work.

EDIT: I'm locking this topic so people start posting new ones. -_-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.