Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
GeneralRe: What do these c# lines mean???? Pin
OriginalGriff7-Jun-15 6:43
mveOriginalGriff7-Jun-15 6:43 
AnswerRe: What do these c# lines mean???? Pin
OriginalGriff7-Jun-15 6:04
mveOriginalGriff7-Jun-15 6:04 
AnswerRe: What do these c# lines mean???? Pin
Ravi Bhavnani9-Jun-15 6:34
professionalRavi Bhavnani9-Jun-15 6:34 
AnswerRe: What do these c# lines mean???? Pin
Gergilcan13-Jun-15 22:01
professionalGergilcan13-Jun-15 22:01 
QuestionError: Operator '>' cannot be applied to operands of type 'double' and 'System.Random' Pin
Member 117477347-Jun-15 2:37
Member 117477347-Jun-15 2:37 
AnswerRe: Error: Operator '>' cannot be applied to operands of type 'double' and 'System.Random' Pin
Sascha Lefèvre7-Jun-15 2:59
professionalSascha Lefèvre7-Jun-15 2:59 
GeneralRe: Error: Operator '>' cannot be applied to operands of type 'double' and 'System.Random' Pin
Member 117477347-Jun-15 3:00
Member 117477347-Jun-15 3:00 
AnswerRe: Error: Operator '>' cannot be applied to operands of type 'double' and 'System.Random' Pin
Dave Kreskowiak7-Jun-15 3:15
mveDave Kreskowiak7-Jun-15 3:15 
AnswerRe: Error: Operator '>' cannot be applied to operands of type 'double' and 'System.Random' Pin
Afzaal Ahmad Zeeshan7-Jun-15 4:24
professionalAfzaal Ahmad Zeeshan7-Jun-15 4:24 
QuestionHow public static declaration for Statusbar Control ? Pin
Member 24584676-Jun-15 23:41
Member 24584676-Jun-15 23:41 
AnswerRe: How public static declaration for Statusbar Control ? Pin
OriginalGriff6-Jun-15 23:57
mveOriginalGriff6-Jun-15 23:57 
QuestionHow to split UTF16 stream Pin
Super Lloyd5-Jun-15 2:22
Super Lloyd5-Jun-15 2:22 
SuggestionRe: How to split UTF16 stream Pin
Richard MacCutchan5-Jun-15 2:29
mveRichard MacCutchan5-Jun-15 2:29 
GeneralRe: How to split UTF16 stream Pin
Super Lloyd5-Jun-15 2:37
Super Lloyd5-Jun-15 2:37 
SuggestionRe: How to split UTF16 stream Pin
Sascha Lefèvre5-Jun-15 2:57
professionalSascha Lefèvre5-Jun-15 2:57 
GeneralRe: How to split UTF16 stream Pin
Super Lloyd5-Jun-15 5:06
Super Lloyd5-Jun-15 5:06 
QuestionTCP Server Multiple Clients (Server Initiation Connection) Pin
MooKowMyke4-Jun-15 12:48
MooKowMyke4-Jun-15 12:48 
AnswerRe: TCP Server Multiple Clients (Server Initiation Connection) Pin
Richard Andrew x644-Jun-15 13:55
professionalRichard Andrew x644-Jun-15 13:55 
GeneralRe: TCP Server Multiple Clients (Server Initiation Connection) Pin
MooKowMyke9-Jun-15 9:04
MooKowMyke9-Jun-15 9:04 
QuestionHelp using EF with DB2 Pin
USAFHokie804-Jun-15 2:56
USAFHokie804-Jun-15 2:56 
AnswerRe: Help using EF with DB2 Pin
Richard MacCutchan4-Jun-15 4:29
mveRichard MacCutchan4-Jun-15 4:29 
QuestionC# Newbie. Need help on coding a errorcheck Pin
Setasigge4-Jun-15 2:24
Setasigge4-Jun-15 2:24 
So, I recently started working with c# without prior coding backround. I am now trying to write a program wich compiles a pdf of different textboxes that the user provides.

I have managed to code the program to check if the boxes are empty, but I am having a hard time trying to make a "ErrorState" if the box is empty.

So here is how it is supposed to go:

User enters text to fields -> Presses btnSave -> Program calls for a method that checks if textboxes are empty, If empty then put program to a "errorstate" and don't call for the next method that saves the pdf. Reset "errorstate" next time btnSave is pressed and check the textboxes again, if all is ok then continue with program.

My problem is getting the "errorstate" out of the method, I get a error: Use of unassigned local variable errorState with my current code. What am I missing, and how wrong Am I using methods? Big Grin | :-D

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Text.RegularExpressions;

namespace CV_maker
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        //============================================================
        //GUI Handling, cheking that user has entered valid information
        //============================================================

        private bool ErrorCheck(bool errorState)

        //Check if txboxName, txtboxBday, txtboxAddres, txtboxPhone, txtboxEmail are empty
 
        {
            bool isError;

            if(txtboxName.Text.Trim().Length == 0)
            { MessageBox.Show("Anna nimesi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxBday.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Syntymäaikasi", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxPhone.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Puhelinnumerosi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxAddress.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Osoitteesi", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxEmail.Text.Trim().Length == 0)
            { MessageBox.Show("Anna S-postisi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            else 
            {
                isError = false;
            }
            return isError;
        }


        //============================================================
        //GUI Handling. Calling up methods
        //============================================================


        //Image Button
        private void btnAddimage_Click(object sender, RoutedEventArgs e)
        {
            addImage();
        }

        //To PDF Button
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bool ISOK;
            bool errorState;
            ISOK = ErrorCheck(errorState);
            if (ISOK == true)
            {
                MessageBox.Show("ERROR I WILL SHOW YOU THIS MESSAGE BEFORE REAL CODE");
            }

            //savepdf();
        }



        //============================================================
        //METHODS Called by GUI
        //===========================================================


        //ADD IMAGE BUTTON
        void addImage()
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Title = "Select a picture";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
              "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
              "Portable Network Graphic (*.png)|*.png";
            if (op.ShowDialog() == true)
            {
                PictureOmakuva.Source = new BitmapImage(new Uri(op.FileName));
            }
            return;
        }

        //Save PDF BUTTON
        void savepdf()

        {
            
                //VARIABLE DECLARATIONS

                string OwnName;

                //PULLING INFORMATION

                OwnName = txtboxName.Text;

                //SAVING THE PDF FILE
                FileStream fs = new FileStream(OwnName + " Curriculum Vitae.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
                Document doc = new Document();
                PdfWriter writer = PdfWriter.GetInstance(doc, fs);
                doc.Open();
                doc.Add(new iTextSharp.text.Paragraph("Tämä on testi"));
                doc.Close();
            
        }


    }
}

AnswerRe: C# Newbie. Need help on coding a errorcheck Pin
Eddy Vluggen4-Jun-15 2:59
professionalEddy Vluggen4-Jun-15 2:59 
AnswerRe: C# Newbie. Need help on coding a errorcheck Pin
Richard MacCutchan4-Jun-15 4:27
mveRichard MacCutchan4-Jun-15 4:27 
GeneralRe: C# Newbie. Need help on coding a errorcheck Pin
Setasigge4-Jun-15 21:04
Setasigge4-Jun-15 21:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.