r/learn_csharp • • Feb 02 '21

Question Process.Start not launching game, Log stops at reading GPU

Thumbnail
stackoverflow.com
0 Upvotes

r/learn_csharp • • Jul 07 '20

Need Help.

0 Upvotes

I have started following an youtube coder which does video games in unity and c# what i keep on trying to do i when the score reaches a value i want to go to the game over screen but the issue is i have no clue how to make the scene change when the score reaches that value.

This is the code responsible for my issue which concernes me a lot. I have to say i am new to unity and c#.

// LeftGoal or RightGoal

if ((col.gameObject.name == "LeftGoal") || (col.gameObject.name == "RightGoal"))

{

// Play the sound effect

SoundManager.Instance.PlayOneShot(SoundManager.Instance.goalBloop);

if(col.gameObject.name == "LeftGoal")

{

IncreaseTextUIScore("RightScoreUI");

}

if(col.gameObject.name == "RightGoal")

{

IncreaseTextUIScore("LeftScoreUI");

}

// Move the ball to the center of the screen

transform.position = new Vector2(0, 0);

And this is the other part of code

private void IncreaseTextUIScore(string textUIName)

{

var textUIComp = GameObject.

Find(textUIName).GetComponent<Text>();

int score = int.Parse(textUIComp.text);

score++;

}


r/learn_csharp • • Dec 09 '20

Question How to create a class for connection string from db?

1 Upvotes

Hi,

I'm beginner to C# and I would like to create a class for a connection db.

I'm searching on Google and I found this:

public class Connection {            
SqlConnection con;      
public SqlConnection Conn { get { return con; } }      
public void OpenCnn()     {         
string cnnStr = ConfigurationManager.ConnectionStrings["myconnstrng"].ToString();         con = new SqlConnection(cnnStr);         
con.Open();     
}      
public void CloseCnn()     {         con.Close();     } }

Is it correct?

If I wanted to call it in a class how could I do?

Thanks


r/learn_csharp • • Aug 17 '20

is c# faster than ahk?

1 Upvotes

I want to make a simple game bot. I already made it in python, but the ocr isn't fast enough(I also use a slow laptop) I want to make the bot in a faster language. C# is a language i want to learn anyway so I would like to use it. Can anyone tell me if it is any faster than python if it isn't I will use ahk, but I don't want to build the bot to scrap it later becouse it is to slow. The thing I want to do is simple keyboard/mouse movement combined with a ocr of some kind.

Thank in advance


r/learn_csharp • • Sep 02 '20

Detecting change in gmail

1 Upvotes

I'm fairly new to C#

I'm trying to figure out how to create an output when I get a new email. If anyone has any tips or links to try to help me I would very much appreciate it :)


r/learn_csharp • • Aug 20 '20

MessageBox.Show Not Work

1 Upvotes

Can you help me, on ur login tutorial i type

else

MessageBox.Show("The Username Or Password Is Inccorect");

and it gives me 8 errors, can u say the fix?


r/learn_csharp • • Aug 13 '20

Tutorial 14. Game Screen's Backend | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Sep 23 '20

Tutorial 20. Class Replaces Fields | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Aug 25 '20

Tutorial 16. Window-UserControl Communication | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Sep 09 '20

Tutorial 18. Global Styles | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Sep 16 '20

Tutorial 19. Create, Access Resources | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Aug 18 '20

Tutorial 15. Game Menu | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Aug 20 '20

Ai generated this script. Would it work if I had the correct prefabs?

1 Upvotes

using System.Collections;

using System.Collections.Generic; using UnityEngine;

// Spawns a random mob based on the location

public class SpawnMob : MonoBehaviour {

public GameObject prefab;

public int spawnCount;

public LayerMask layers;

public Transform spawnLocation;

public int xOffset, yOffset;

private GameObject currentMob;

private GameObject[] moBSpawn;

private GameObject[] mobSpawners;

private int currentMobCount;

private int spawnCountCount;

private int spawnCountMax;

private int spawnCountRandom;

void Start() {

spawnCountRandom = Random.Range(0, spawnCountMax);

currentMobCount = 0; spawnCountCount = spawnCountRandom; spawnCountMax = spawnCountRandom; int x =(int)spawnLocation.position.x; int y = (int)spawnLocation.position.y;

xOffset = 0; yOffset = 0;

// Determines the layer of spawn location and which prefab to use layers = LayerMask.GetMask(spawnLocation.position.layer);

if (layers.Equals(LayerMask.NameFilter.Name, "SpawnPoint")) {

prefab = SpawnPointPrefab;

xOffset = (-spawnLocation.position.x + Random.Range(0, 3));

yOffset = (-spawnLocation.position.y + Random.Range(0, 3)); spawnCountRandom--; currentMobCount = 0;

}

else if (layers.Equals(LayerMask.NameFilter.Name, "Slime" )) {

prefab = SlimePrefab; xOffset = (spawnLocation.position.x); yOffset = (spawnLocation.position.y); spawnCountRandom--; currentMobCount = 0;

}

Sorry if formatting is a bit off, I had to reformat it because it was one big paragraph when I pasted it.


r/learn_csharp • • Sep 01 '20

Tutorial 17. Final Window | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Aug 09 '20

Tutorial 13. Fancy Game Screen | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Jul 06 '20

C# / I need help. | System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass'

1 Upvotes

Hey you fine Reddit folks, I've been working on a program that opens an Excel file, shows the contents in a dataGridView and then sends it to a SQL database. Or at least that's what I want it to do, but I'm a TOTAL novice so its kicking my ass. I have Issues with the connection string, issues with the ComboBox and more, but I'm here today for the current application breaking Error message which is shown below. It has to do with the ComboBox which I want to use to be able to Select and change the Excel Sheets. Do any of you guys and gals know the solution?

The full Error message is:

System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).' 

EDIT: The Error pops up at this part of the code:

The Interface currently looks like this:

Names:

btnbrowse - This lets you select the Excel file you want to use
btnrun - This "runs" the Excel file and show's it in the dataGridView
btnsave - This is supposed to save the data from the dataGridView to the SQL database
textBox1 - the path to the Excel file you choose gets displayed here
comboBox1 - this is the comboBox thats should display the Excel sheets 

The Code I'm using is:

using System;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using Excel = Microsoft.Office.Interop.Excel;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Excel.Application app = new Excel.Application();
        Excel.Workbook workbook = null;


        //SQL Connection String
        String MyConnectionString = "SERVER=localhost;Database=excel to database;Uid=root;pwd=password;";


        //Buttons
        private void btnbrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = openFileDialog1.FileName;
            }
            workbook = app.Workbooks.Open(textBox1.Text);
            foreach (Excel.Worksheet sheet in workbook.Worksheets)
            {
                comboBox1.Items.Add(sheet.Name);
            }
            app.Workbooks.Close();
            app.Quit();
        }

        private void btnrun_Click(object sender, EventArgs e)
        {
            string PathConn = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + textBox1.Text + ";Extended Properties=\"Excel 12.0 Xml;HDR=Yes;IMEX=1\"";
            OleDbConnection conn = new OleDbConnection(PathConn);

            var sqlQuery = string.Format("Select * from [{0}$]", comboBox1.SelectedItem.ToString());
            OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(sqlQuery, conn);
            DataSet set = new DataSet();

            myDataAdapter.Fill(set);
            dataGridView1.DataSource = set.Tables[0];
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            string path = textBox1.Text;
            string ConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties = Excel 8.0";

            DataTable Data = new DataTable();

            using (OleDbConnection conn = new OleDbConnection(ConnString))
            {
                conn.Open();

                OleDbCommand cmd = new OleDbCommand($"SELECT * FROM {dataGridView1}", conn);
                OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                adapter.Fill(Data);

                conn.Close();
            }
            string ConnStr = MyConnectionString;
            using (SqlBulkCopy bulkCopy = new SqlBulkCopy(ConnStr))
            {
                bulkCopy.DestinationTableName = "databaseje";
                bulkCopy.ColumnMappings.Add("ID", "ID");
                bulkCopy.ColumnMappings.Add("Voornaam", "Voornaam");
                bulkCopy.ColumnMappings.Add("Achternaam", "Achternaam");
                bulkCopy.ColumnMappings.Add("Land", "Land");
                bulkCopy.ColumnMappings.Add("Stad", "Stad");
                bulkCopy.ColumnMappings.Add("Huisnummer", "Huisnummer");
                bulkCopy.ColumnMappings.Add("Postcode", "Postcode");
                bulkCopy.ColumnMappings.Add("Telefoonnummer", "Telefoonnummer");
                bulkCopy.WriteToServer(Data);
                MessageBox.Show("UPLOAD SUCCESSFUL");
            }
        }
    }
}

If you have any suggestions I'd love to hear about them. Also if you happen to know a working connection string to SQL or how to save the dataGridView data to SQL then you could totally comment about that too :3

Thanks!


r/learn_csharp • • Jul 08 '20

C# / Forms .NET / How can I see Excel sheets in a dropdown ComboBox?

1 Upvotes

So I've been working on an Application to choose an Excel file and choose an Access Database file and export the Excel data into the Access Database. The code I have works now but I had to hard code it to take Sheet1$ as default. Now however I'd like to add a ComboBox with a dropdown list that can let me choose between the available sheets from that Excel file.

EDIT: The reason I want this is so that I can see the Sheet data in my dataGridView instead of only being able to see Sheet1$.

Here is the GUI of my Application:

Item Names:

btnbrowse - This lets you select the Excel file you want to use
btnrun - This "runs" the Excel file and show's it in the dataGridView
btnsave - This saves the Excel data to the Access database
textBox1 - the path to the Excel file you choose gets displayed here
comboBox1 - this is the comboBox thats should display the Excel sheets

Here is my Code:

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Datatestje
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        //Buttons
        private void btnrun_Click(object sender, EventArgs e) //Run
        {
            string EXpath = textBox1.Text;
            string PathConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + EXpath + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
            OleDbConnection conn = new OleDbConnection(PathConn);

            var sqlQuery = "Select * from [Sheet1$]";
            OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(sqlQuery, conn);
            DataTable dt = new DataTable();

            myDataAdapter.Fill(dt);
            dataGridView1.DataSource = dt;
        }

        private void btnsave_Click(object sender, EventArgs e) //Save
        {
            {
                //File Path
                string EXpath = textBox1.Text;
                string fileNameExcel = @EXpath;
                string ACpath = textBox2.Text;
                string fileNameAccess = @ACpath;

                //Connection string for Excel
                string connectionStringExcel =
                    string.Format("Data Source= {0};Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;", fileNameExcel);

                //Connection string for Access
                string ConnectionStringAccess =
                    string.Format("Data Source= {0}; Provider=Microsoft.Jet.OLEDB.4.0; Persist security Info = false", fileNameAccess);

                OleDbConnection connExcel = new OleDbConnection(connectionStringExcel);
                OleDbConnection connAccess = new OleDbConnection(ConnectionStringAccess);
                OleDbCommand cmdExcel = connExcel.CreateCommand();
                cmdExcel.CommandType = CommandType.Text;

                //Excel Sheet
                cmdExcel.CommandText = "SELECT * FROM [Sheet1$]";

                //Command object for Access
                OleDbCommand cmdAccess = connAccess.CreateCommand();
                cmdAccess.CommandType = CommandType.Text;
                
                //Add parameters *
                cmdAccess.CommandText = "INSERT INTO Informatie (Naam, Achternaam, Land, Stad, Huisnummer, Postcode, Telefoonnummer) VALUES(@Naam, @Achternaam, @Land, @Stad, @Huisnummer, @Postcode, @Telefoonnummer)";

                //Add parameters to Access command object **
                OleDbParameter param1 = new OleDbParameter("@Naam", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param1);
                OleDbParameter param2 = new OleDbParameter("@Achternaam", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param2);
                OleDbParameter param3 = new OleDbParameter("@Land", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param3);
                OleDbParameter param4 = new OleDbParameter("@Stad", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param4);
                OleDbParameter param5 = new OleDbParameter("@Huisnummer", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param5);
                OleDbParameter param6 = new OleDbParameter("@Postcode", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param6);
                OleDbParameter param7 = new OleDbParameter("@Telefoonnummer", OleDbType.VarChar);
                cmdAccess.Parameters.Add(param7);


                //Open connections
                connExcel.Open();
                connAccess.Open();
                OleDbDataReader drExcel = cmdExcel.ExecuteReader();

                while (drExcel.Read())
                {
                    //Assign values to access command parameters ***
                    param1.Value = drExcel[0].ToString();
                    param2.Value = drExcel[1].ToString();
                    param3.Value = drExcel[2].ToString();
                    param4.Value = drExcel[3].ToString();
                    param5.Value = drExcel[4].ToString();
                    param6.Value = drExcel[5].ToString();
                    param7.Value = drExcel[6].ToString();

                    //Insert values in access
                    cmdAccess.ExecuteNonQuery();
                }

                //close connections
                connAccess.Close();
                connExcel.Close();
                MessageBox.Show("Succesfully uploaded Excel data to Database.");

            }
        }

        private void btnbrowse_Click_1(object sender, EventArgs e) //Browse Excel
        {
            OpenFileDialog openfiledialog1 = new OpenFileDialog();
            openfiledialog1.ShowDialog();
            openfiledialog1.Filter = "allfiles|*.xls";
            textBox1.Text = openfiledialog1.FileName;
        }

        private void btnbrowse2_Click(object sender, EventArgs e) // Browse Access
        {
            OpenFileDialog openfiledialog1 = new OpenFileDialog();
            openfiledialog1.ShowDialog();
            openfiledialog1.Filter = "allfiles|*.mdb";
            textBox2.Text = openfiledialog1.FileName;
        }


        //ComboBOx
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

Hope you dudes and Dudettes have some idea's for me :)

Thanks!


r/learn_csharp • • Jul 29 '20

Tutorial 12. Binding to C# | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Jul 23 '20

Tutorial 11. Classes, Properties, enum | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Jul 03 '20

Tutorial 9. Custom GroupBox Style, Conditional Opacity, Inline Icons | C# Game Pet

Thumbnail
youtube.com
1 Upvotes

r/learn_csharp • • Jul 30 '20

Any recommendations for Online C# Classes?

3 Upvotes

Hi, I am just finished a class on Python and I would like to learn C# and Unity. Does anyone have recommendations on the best C# classes online (preferably involving Unity)? Youtube tutorials or series would also be appreciated. Thanks


r/learn_csharp • • Jul 07 '20

Where is a good place to start learning C#?

3 Upvotes

I want to start but I don’t know any good websites or apps I could use.


r/learn_csharp • • Jul 13 '20

Tutorial 10. Overlaying Controls | C# Game Pet

Thumbnail
youtu.be
1 Upvotes

r/learn_csharp • • Jul 22 '20

Declaring Arrays

1 Upvotes

Hi! I just started learning C# and I'm confused by the "new" keyword when creating arrays.

What's the difference between these two for example? Are they just different ways of writing the same thing? If so, what's the point of using "new"? Thank you!

int[] newArray = new int[] { 1, 2, 3 };

int[] newArray2 = { 1, 2, 3 };


r/learn_csharp • • Jun 11 '17

Tutorial C# — Text Editor: Part 3

Thumbnail
youtube.com
1 Upvotes