-4

I am relatively new to programming and have started to code in C#, now. I am making a tiny program, that I want to consist of just a single *.exe file. The program is a windows form with some pictures on it, there are some default starting ones and others that need to be shown under certain conditions. Basically they are the same PictureBox(es) that I just change with PictureBox.Image = System.Drawing.Image.FromFile(@"C:\teh image.jpg");

I used the "Choose Image" option on the Picture Boxes to locate each default picture on my hard drive and have, sort of, found out that they are included in the *.exe file, beacuse if I change the folder's name (the one containing the pictures) the program runs smoothly. I want to do the same for the other pictures that I need to be shown later, I thought that maybe after I included my .image.fromfile, etc. the all-wise compilator will see it and include the other pictures, as well, but it did not. So I want to know how I can do that.

As a bonus question, there seems to be an error in my code:

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

namespace Heroes5_ArmyCalc
{
    public partial class Form1 : Form
    {
        int Current_Tier1_01_Gold=3333;
        int Current_Tier1_02_Gold;
        int Current_Tier2_01_Gold;
        int Current_Tier2_02_Gold;
        int Current_Tier3_01_Gold;
        int Current_Tier3_02_Gold;
        int Current_Tier4_01_Gold;
        int Current_Tier4_02_Gold;
        int Current_Tier5_01_Gold;
        int Current_Tier5_02_Gold;
        int Current_Tier6_01_Gold;
        int Current_Tier6_02_Gold;
        int Current_Tier7_01_Gold;
        int Current_Tier7_02_Gold;
        int Current_Tier1_Pop;
        int Current_Tier2_Pop;
        int Current_Tier3_Pop;
        int Current_Tier4_Pop;
        int Current_Tier5_Pop;
        int Current_Tier6_Pop;
        int Current_Tier7_Pop;
        int Haven_Tier1_01_Gold = 15;
        int Haven_Tier1_02_Gold = 25;
        int Haven_Tier2_01_Gold = 50;
        int Haven_Tier2_02_Gold = 80;
        int Haven_Tier3_01_Gold = 85;
        int Haven_Tier3_02_Gold = 130;
        int Haven_Tier4_01_Gold = 250;
        int Haven_Tier4_02_Gold = 370;
        int Haven_Tier5_01_Gold = 600;
        int Haven_Tier5_02_Gold = 850;
        int Haven_Tier6_01_Gold = 1300;
        int Haven_Tier6_02_Gold = 1700;
        int Haven_Tier7_01_Gold = 2800;
        int Haven_Tier7_02_Gold = 3500;
        int Haven_Tier1_Pop = 22;
        int Haven_Tier2_Pop = 12;
        int Haven_Tier3_Pop = 10;
        int Haven_Tier4_Pop = 5;
        int Haven_Tier5_Pop = 3;
        int Haven_Tier6_Pop = 2;
        int Haven_Tier7_Pop = 1;

        public Form1()
        {
            InitializeComponent();
            Current_Haven();
            Basics();
        }

        public void Basics()
        {
            Gold_Tier1.Text = Convert.ToString(Current_Tier1_01_Gold);
            Gold_Tier2.Text = Convert.ToString(Current_Tier2_01_Gold);
            Gold_Tier3.Text = Convert.ToString(Current_Tier3_01_Gold);
            Gold_Tier4.Text = Convert.ToString(Current_Tier4_01_Gold);
            Gold_Tier5.Text = Convert.ToString(Current_Tier5_01_Gold);
            Gold_Tier6.Text = Convert.ToString(Current_Tier6_01_Gold);
            Gold_Tier7.Text = Convert.ToString(Current_Tier7_01_Gold);
            Pop_Tier1.Text = Convert.ToString(Current_Tier1_Pop);
            Pop_Tier2.Text = Convert.ToString(Current_Tier2_Pop);
            Pop_Tier3.Text = Convert.ToString(Current_Tier3_Pop);
            Pop_Tier4.Text = Convert.ToString(Current_Tier4_Pop);
            Pop_Tier5.Text = Convert.ToString(Current_Tier5_Pop);
            Pop_Tier6.Text = Convert.ToString(Current_Tier6_Pop);
            Pop_Tier7.Text = Convert.ToString(Current_Tier7_Pop);
        }

        public void Current_Haven()
        {
            int Current_Tier1_01_Gold = Haven_Tier1_01_Gold;
            int Current_Tier1_02_Gold = Haven_Tier1_02_Gold;
            int Current_Tier2_01_Gold = Haven_Tier2_01_Gold;
            int Current_Tier2_02_Gold = Haven_Tier2_02_Gold;
            int Current_Tier3_01_Gold = Haven_Tier3_01_Gold;
            int Current_Tier3_02_Gold = Haven_Tier3_02_Gold;
            int Current_Tier4_01_Gold = Haven_Tier4_01_Gold;
            int Current_Tier4_02_Gold = Haven_Tier4_02_Gold;
            int Current_Tier5_01_Gold = Haven_Tier5_01_Gold;
            int Current_Tier5_02_Gold = Haven_Tier5_02_Gold;
            int Current_Tier6_01_Gold = Haven_Tier6_01_Gold;
            int Current_Tier6_02_Gold = Haven_Tier6_02_Gold;
            int Current_Tier7_01_Gold = Haven_Tier7_01_Gold;
            int Current_Tier7_02_Gold = Haven_Tier7_02_Gold;
            int Current_Tier1_Pop = Haven_Tier1_Pop;
            int Current_Tier2_Pop = Haven_Tier2_Pop;
            int Current_Tier3_Pop = Haven_Tier3_Pop;
            int Current_Tier4_Pop = Haven_Tier4_Pop;
            int Current_Tier5_Pop = Haven_Tier5_Pop;
            int Current_Tier6_Pop = Haven_Tier6_Pop;
            int Current_Tier7_Pop = Haven_Tier7_Pop;
            Basics();
        }
    [some other code]

I have cleared all code that is not relevant at this time. Points of interest:

  • notice that the variable "Current_Tier1_01_Gold" is given a value at the start.
  • it should be that when "Current_Heaven" is called, it makes it so that "Current_Tier1_01_Gold" is assigned the new value of "Haven_Tier1_01_Gold", which is "15"
  • when "Basics" is called, it should make the text "Gold_Tier1" be that of "Current_Tier1_01_Gold"

problems: - the text of "Gold_Tier1" is "3333" - the initial value of "Current_Tier1_01_Gold", even after "Current_Heaven" is called.

If need be, I can provide the full code, but it is 703 lines long.

Dmitry
  • 13,797
  • 6
  • 32
  • 48
  • 4
    You should not have a separate "bonus question". If you have two different questions, ask them separately. – Eric J. Apr 23 '14 at 20:22
  • 6
    And you REALLY should look into arrays... – kat0r Apr 23 '14 at 20:23
  • 3
    I think adding all that code/"bonus" question has distracted everyone from answering the original question. Maybe you should take it out – eddie_cat Apr 23 '14 at 20:25

2 Answers2

1

Yes, you can integrate files into your project by using resources.

That being said, you should get some books about basic programming and especially arrays.You did however not deserve to be ridiculed in the comments, guys.

Community
  • 1
  • 1
kat0r
  • 949
  • 8
  • 17
  • Wow, thanks! I did search around for an answer, but did not find one. :) But why all the arrays? Thanks for defending me! :P – user3566162 Apr 23 '14 at 20:35
  • As far as the problem in your code goes, changing the value of Current_Tier1_01_Gold in Current_Heaven will not affect the int you assigned to the original value of Current_Tier1_01_Gold. This is because int is a value type so every new int instance creates a new copy of the value. They are not referring to the same thing. – eddie_cat Apr 23 '14 at 20:37
  • Actually that's not quite right. When you assign the int value to the Text property, you are creating a new string. This string is not affected by a change to the original int. So they're not referring to the same thing, but not for the reason I cited above. – eddie_cat Apr 23 '14 at 20:39
  • @user3566162 Using arrays you won't need to make 10 `Current_TierX_0X_Gold` variables – Cyral Apr 23 '14 at 20:41
  • Savanna King, Wait, what?! Why not?! And how do I change it, then? :D – user3566162 Apr 23 '14 at 20:41
  • Cyral, yeah, but it's much easier to keep track of all the different values without arrays in this case. Is it not? – user3566162 Apr 23 '14 at 20:42
  • Because you are creating a new string. The string, after being created, has nothing to do with the integer you made it from. You can change the value of the integer, but you will have to also change the string to reflect the new value. When you call Current_Haven, also update the Text value there after changing the int. Let me know if this doesn't make sense, I can write a more complete answer instead of using comments. – eddie_cat Apr 23 '14 at 20:42
  • No. Arrays look almost the same as your code does now, but improve readability, make some parts trivial, and also allow for adding new tiers/values. Google some tutorials, like http://msdn.microsoft.com/en-us/library/aa288453%28v=vs.71%29.aspx – kat0r Apr 23 '14 at 20:43
  • @SavannaKing, sorry can you give me one line of example code? – user3566162 Apr 23 '14 at 20:45
  • @kat0r I see your point, I know enough about arrays, but this felt better to me. I will look into remaking it with arrays. – user3566162 Apr 23 '14 at 20:46
  • See my answer, was easier to post that way – eddie_cat Apr 23 '14 at 20:50
0

I'm going to post an example here for your "bonus question" because formatting is easier than in comments.

public void Current_Haven()
{
    int Current_Tier1_01_Gold = Haven_Tier1_01_Gold;
    //You need to add this line here for the Text to be updated.
    Gold_Tier1.Text = Convert.ToString(Current_Tier1_01_Gold);

}

Now, calling Current_Haven will update the Text property as you want it to.

eddie_cat
  • 2,527
  • 4
  • 25
  • 43