Menu
  • HOME
  • TAGS

Quiz not declared and maybe inaccessible

Tag: vb.net,winforms,forms

Not Sure Why Im getting Quiz not declared error?(see bold Quiz) Can I get some help with this please. Ive tried to declare Quiz several different ways but Im stuck. This Quiz is going to be modified more in the Questions and answers part as I want to use this template as a bible study tool. Thanks for your help.

Option Strict On
Public Class Form2
Dim TestAboutMe As New Quiz3x
Friend WithEvents QuizStart, AnswerSubmit As New System.Windows.Forms.Button
Friend WithEvents RadioButton1, RadioButton2, RadioButton3, RadioButton4 As New System.Windows.Forms.RadioButton
Friend WithEvents Label1 As New System.Windows.Forms.Label

Sub ResetQuiz()
    TestAboutMe.Clear()
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 1 ?", {"2", "3", "5", "7"}.ToList, "2"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 2 ?", {"3", "5", "4", "7"}.ToList, "4"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 3 ?", {"6", "99", "7", "1"}.ToList, "6"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 4 ?", {"8", "0", "9", "2"}.ToList, "8"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 5 ?", {"12", "10", "5", "7"}.ToList, "10"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 6 ?", {"6", "66", "666", "12"}.ToList, "12"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 7 ?", {"13", "15", "14", "55"}.ToList, "14"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 8 ?", {"15", "14", "17", "16"}.ToList, "16"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 9 ?", {"17", "18", "12", "33"}.ToList, "18"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 10 ?", {"20", "18", "19", "22"}.ToList, "20"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 11 ?", {"23", "24", "22", "32"}.ToList, "22"))
    TestAboutMe.AddQuestion(Quiz.Question("What is 2 x 12 ?", {"23", "24", "25", "12"}.ToList, "24"))
    RadioButton1.Checked = False : RadioButton2.Checked = False
    RadioButton3.Checked = False : RadioButton4.Checked = False
    RadioButton1.Visible = True : RadioButton2.Visible = True
    RadioButton3.Visible = True : RadioButton4.Visible = True
End Sub
End Class

Public Class Quiz3x
Private Property _Questions As New List(Of Question)
Private Index As Integer = 0
Private _CurrentQuestion As Question
Private Property _CorrectAnswers As Integer = 0
Private Property _TestComplete As Boolean = False
Public ReadOnly Property TestComplete As Boolean
    Get
        Return _TestComplete
    End Get
End Property

Public ReadOnly Property CurrentQuestion As Question
    Get
        Return _CurrentQuestion
    End Get
End Property
Public ReadOnly Property TotalQuestions As Integer
    Get
        Return _Questions.Count
    End Get
End Property
Public ReadOnly Property CorrectAnswers As Integer
    Get
        Return _CorrectAnswers
    End Get
End Property
Public ReadOnly Property Questions As List(Of Question)
    Get
        Return _Questions
    End Get
End Property
Public Sub NextQuestion()
    Dim TmpIndex As Integer = Index
    Index = Index + 1
    If TmpIndex > Questions.Count - 1 Then
        _TestComplete = True
        Exit Sub
    End If
    _CurrentQuestion = Questions(TmpIndex)
End Sub
Public Sub AddQuestion(ByVal Question As Question)
    _Questions.Add(Question)
End Sub
Public Sub GradeQuestion(ChosenAnswer As String)
    If ChosenAnswer = CurrentQuestion.CorrectAnswer Then
        _CorrectAnswers = _CorrectAnswers + 1
    End If
End Sub
Public Sub Clear()
    _Questions.Clear()
    Index = 0
    _CorrectAnswers = 0
    _TestComplete = False
End Sub
Class Question
    Private _Question As String
    Private _Choices As New List(Of String)
    Private _CorrectAnswer As String
    Public ReadOnly Property Question As String
        Get
            Return _Question
        End Get
    End Property
    Public ReadOnly Property Choices As List(Of String)
        Get
            Return _Choices
        End Get
    End Property
    Public ReadOnly Property CorrectAnswer As String
        Get
            Return _CorrectAnswer
        End Get
    End Property
    Sub New(Question As String, Choices As List(Of String), CorrectAnswer As String)
        _Question = Question
        _Choices = Choices
        _CorrectAnswer = CorrectAnswer
    End Sub
End Class
End Class

This is form 2 Form 1 has a button that is a msgbox

Best How To :

In Sub ResetQuiz() change every

TestAboutMe.AddQuestion(Quiz.Question(...

to

TestAboutMe.AddQuestion(New Quiz.Question(...

Filtering Last Duplicate Occurrence In A Datatable

c#,vb.net

You can use LINQ: DataTable nonDups = parsedDataset.Tables("Detail").AsEnumerable() .GroupBy(row => row.Field<string>("Authorization_ID")) .OrderBy(grp => grp.Key) .Select(grp => grp.Last()) .CopyToDataTable(); This selects the last row of each dup-group. If you want to order the group use grp.OrderBy....

How to pass all value of ListBox Control to a function?

vb.net,listbox

You're passing the contents of a ListBox to a method that is just displaying them in a MsgBox(). There are two approaches you can do to accomplish what I think you're wanting. You can pass ListBox.Items to the method and iterate through each item concatenating them into a single String...

Get XML node value when previous node value conditions are true (without looping)

xml,vb.net,linq-to-xml

UPDATE Using an XDocument vs an XmlDocument, I believe this does what you're asking without using loops. This is dependent on the elements being in the order of <PhoneType> <PhonePrimaryYN> <PhoneNumber> string xml = "<?xml version=\"1.0\"?>" + "<Root>" + " <PhoneType dataType=\"string\">" + " <Value>CELL</Value>" + " </PhoneType>" + "...

Automapper AfterMap function initialising classes

.net,vb.net,automapper

The objects have values in them because they are called after Mapping.Map function is called and that's where actual object with values is passed and then AfterMap function is called and that's how it has the values in it.

DialogBox with value verifications

c#,.net,winforms

The problem is you're trying to enable or disable the button when checking individual textboxes and they're conflicting with each other, instead the logic needs to be at a higher level. Change your textbox validation function to return a bool, and use that in ValidateAll to determine whether or not...

How to create a folder that contains the current date and time instead of name

winforms,visual-studio-2013,c++-cli

Don't hard-code the desktop directory name, it is not c:\users\desktop. .NET makes it easy: String^ path = System::IO::Path::Combine( Environment::GetFolderPath(System::Environment::SpecialFolder::Desktop), DateTime::Now.ToString("yyyyMMddhhmmss")); System::IO::Directory::CreateDirectory(path); // Write file(s) to <path> //... It is up to you to decide how fine-grained to make the directory name, if you do this at a very high rate...

How can i get list of my youtube videos from youtube?

c#,.net,winforms,youtube,youtube-api

You're trying to call a v2 URL (the one that starts with https://gdata), which no longer exists. Additionally, the location you got a developer key from is also deprecated; you won't use a "developer key," but the API key you get from console.developers.google.com -- NOT the client ID, though. You...

Retrieve full path of FTP file on drag & drop?

vb.net,ftp

If the data dropped contains a UniformResourceLocator format, you can get the entire URL from that, for example: Private Sub Form1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop If e.Data.GetDataPresent("UniformResourceLocator") Then Dim URL As String = New IO.StreamReader(CType(e.Data.GetData("UniformResourceLocator"), IO.MemoryStream)).ReadToEnd End If End Sub It first checks to see if a...

Removing Alert When Using DeleteFile API

vb.net,vba,api,delete

There are several SHFILEOPSTRUCT.fFlags options you'll want to consider. You are asking for FOF_NOCONFIRMATION, &H10. You probably want some more, like FOF_ALLOWUNDO, FOF_SILENT, FOF_NOERRORUI, it isn't clear from the question. Check the docs.

Set Label From Thread

vb.net,multithreading,winforms

The reason is that you are referring to the default instance in your second code snippet. Default instances are thread-specific so that second code snippet will create a new instance of the Form1 type rather then use the existing instance. Your Class1 needs a reference to the original instance of...

Application is missing required files

c#,.net,windows,winforms,sharpdevelop

Your program is looking for compas.ico inside the build directory, while it probably resides in some other directory in your project.

Can't output Guid Hashcode

sql,vb.net,guid,hashcode

Well, are you looking for a hashcode like this? "OZVV5TpP4U6wJthaCORZEQ" Then this answer might be useful: Guid g = Guid.NewGuid(); string GuidString = Convert.ToBase64String(g.ToByteArray()); GuidString = GuidString.Replace("=",""); GuidString = GuidString.Replace("+",""); Extracted from here. On the linked post there are many other useful answers. Please take a look! Other useful links:...

How to use XDocument to get attributes and add them to a List

c#,xml,winforms,list

The attributes you're trying to get aren't attribute of Payments element. You need to go one level deeper to get them. Try this way : ...... doc = XDocument.Load(reader); var data = doc.Root .Elements() .Elements("Payments"); foreach(var d in data) { var patti = d.Element("Patti"); list1.Add(new List<string>() { patti.Attribute("Rent").Value, patti.Attribute("Water").Value, patti.Attribute("Electricity").Value,...

Scraping Javascript webpage (script error occurred)

javascript,html,vb.net,web,scrape

You can use WebBrowser.ScriptErrorsSuppressed = true; property. Details: https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.scripterrorssuppressed%28v=vs.110%29.aspx...

How to make inherited form full screen [on hold]

c#,winforms

You have to decide: Either maximize the form (which always makes sure the TaskBar is still visible) or set the dimensions manually. I suggest you remove the WindowState line. Another failsafe way would be to hide the TaskBar from your code, for example as described here....

how can i use parameters to avoid sql attacks

sql,vb.net

I think the only solution is create a new function and gradually migrate to it. Public Function ExecuteQueryReturnDS(ByVal cmdQuery As SqlCommand) As DataSet Try Dim ds As New DataSet Using sqlCon As New SqlConnection(connStr) cmdQuery.Connection = sqlCon Dim sqlAda As New SqlDataAdapter(cmdQuery) sqlAda.Fill(ds) End Using Return ds Catch ex As...

getting keyboard input in winform listbox

c#,winforms,keyevent

private void listBox1_KeyPress(object sender, KeyPressEventArgs e) { string letter = ""; //letter = ProcessKey(e.KeyChar); //or letter = e.KeyChar.ToString(); } private string ProcessKey(char key) { return key.ToString(); } ...

Comparing arrays with numbers in vb.net

arrays,vb.net

There are a few basic ways of checking for a value in an integer array. The first is to manually search by looping through each value in the array, which may be what you want if you need to do complicated comparisons. Second is the .Contains() method. It is simpler...

How to change background Color of label full length when Mouse Hover in c#

c#,winforms

select the label then goto autosize and set it to false... then increase the length of the label as much as you want... then apply your above code... it'll work.. All the best...

Syntax error in Insert query in Mysql in VB.Net

mysql,vb.net

you miss the closing parenthesis for the values list: Dim cmd1 As New OdbcCommand("insert into party values('" + pcode_txt.Text + "','" + Trim(UCase(name_txt.Text)) + "','" + Trim(UCase(addr_txt.Text)) + "','" + phone_txt.Text + "','" + combo_route.SelectedItem + "','" + combo_area.SelectedItem + "')", con) My answer is perfectly fit to your question...

vb.net AES decryption returns “data is incomplete block”

vb.net,encryption,cryptography,aes

Despite all comments, I still lack understanding of your intentions. Therefore, the sample code below may not provide what you exactly want, but at least should give an idea how to employ cryptographic functions. Particularly, the most notable difference from your approach is that the encryption key and initialization vector...

Visual Basic Datagrid View change row colour

vb.net,datagridview,datagrid

Is it possible that your datagridview isn't loaded fully when you try to recolor the rows? Since you are setting the datasource, you should put your code that affects the grid after you can make sure that it is finished loading. The column widths change because it is not dependent...

Updating a list of objects bound to a DataGridView from a popup form

c#,winforms,datagridview

If the databound item does not contain notify property changed events, the user interface (datagridview) won't know anything has changed. You'll have to trigger the refresh manually. Either the entire grid or source or something like dataGridBasket.InvalidateRow(row.Index)

Custom drawing using System.Windows.Forms.BorderStyle?

c#,.net,vb.net,winforms,custom-controls

If you want to get results that reliably look like the BorderStyles on the machine you should make use of the methods of the ControlPaint object. For testing let's do it ouside of a Paint event: Panel somePanel = panel1; using (Graphics G = somePanel.CreateGraphics()) { G.FillRectangle(SystemBrushes.Window, new Rectangle(11, 11,...

Convert date to string format

vb.net,converter

Your approach doesn't work because you are using ToString on a DataColumn which has no such overload like DateTime. That doesn't work anyway. The only way with the DataTable was if you'd add another string-column with the appropriate format in each row. You should instead use the DataGridViewColumn's DefaultCellStyle: InvestorGridView.Columns(1).DefaultCellStyle.Format...

WPF style info from external text file

wpf,vb.net,styles

just hold the color values in a config file simple text file will suffice. though you can use VisualStudio Resource file.. file will contain lines in each: item_enum_name item_type item_value for example: main_screen_bg_color Color Black company_logo URI \logos\logo1.jpg and so on.. just load the file parse it and use bind...

VB.net: How to define a namespace where the first segment is NOT the file name?

vb.net

Remove the Root namespace from the project properties: ...

Where to store an mp4 file in my project?

.net,vb.net,visual-studio,mp4

Try going Project>"Project Name" Properties>Resources>Add Resource>Add Existing File This should add the file into your resources folder. You can then access any file by going My.Resources.Name_Of_Resource...

NullReference Error while assiging values of Modeltype in MVC View (Razor)

vb.net,razor,model-view-controller,model

You need to pass the model instance to the view: Function Details() As ActionResult Dim employee As Employee employee = New Employee employee.EmployeeID = 101 Return View(employee) End Function ...

Regex to check if string is alphanumeric separated by commas or a single alphanumeric string

regex,vb.net

^\d{1,2}[A-Z]?(?:,\d{1,2}[A-Z]?)*$ Try this.See demo. https://regex101.com/r/hI0qP0/25...

ZipEntry() and converting persian filenames

vb.net,persian,sharpziplib

Try setting IsUnicodeText to true: 'VB.NET Dim newEntry = New ZipEntry(entryName) With { _ Key .DateTime = DateTime.Now, _ Key .Size = size, _ Key .IsUnicodeText = True _ } //C# var newEntry = new ZipEntry(entryName) { DateTime = DateTime.Now, Size = size, IsUnicodeText = true }; ...

Gridview items not populating correctly

asp.net,vb.net

Try this vb code behind, then comment out my test Private Sub BindGrid() Dim dt_SQL_Results As New DataTable '' Commenting out to use test data as I have no access to your database 'Dim da As SqlClient.SqlDataAdapter 'Dim strSQL2 As String 'Dim Response As String = "" 'strSQL2 = "SELECT...

How to execute four queries once and then check success or failure?

vb.net,windows,visual-studio-2010,ms-access

There a number of other problems with the code (sql injection, sharing a connection among several commands), but here's a step in the right direction: Try conn.Open() cmdfoods.ExecuteNonQuery() cmdservices.ExecuteNonQuery() cmdreservations.ExecuteNonQuery() bill.ExecuteNonQuery() success = True Catch success = False Finally conn.Close() End Try A more-complete solution: Private Function save_to_data() Dim sql...

How can i put formclosing event in Button

c#,winforms

You could define a variable which goes to true when you press the button and check on close if the variable is true e.g. private bool btnClicked = false; public void btnChallenge_Click(object sender, EventArgs e) { btnClicked = true; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if(btnClicked) { e.Cancel=true;...

Custom Numericupdown

c#,winforms,custom-controls

Well, you don't have enough code. Not so sure I'd recommend this, moving the "focus" from one value to another isn't exactly very intuitive. You'll get better UI from simply using two NUDs. Anyhoo, some code to play with: using System; using System.ComponentModel; using System.Windows.Forms; using System.Globalization; class RangeUpDown :...

C# Windows Form Application - value not printing in textbox for each time

c#,winforms,textbox,windows-forms-designer,form-control

In C# Window application, control values are render after event is executed. After your click event textbox is displaying last value that is updated. If you want to render text-box value during event execution.You have to call refresh method of text-box to render value. Use this.. You have to refresh...

Return index of word in string

arrays,vb.net,vbscript

Looking at your desired output it seems you want to get the index of word in your string. You can do this by splitting the string to array and then finding the item in an array using method Array.FindIndex: Dim animals = "cat, dog, bird" ' Split string to array...

Move windows form from a picturebox in C#

c#,.net,winforms,picturebox

Refer this code: private bool draging = false; private Point pointClicked; private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (draging) { Point pointMoveTo; pointMoveTo = this.PointToScreen(new Point(e.X, e.Y)); pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y); this.Location = pointMoveTo; } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { draging = true;...

Managing per form ObjectContext lifetime

c#,winforms,entity-framework,orm

As strange as it sounds ,you don't have to dispose you DbContext (IF you haven't manually opened the connection yourself) Have a look at this: Do I always have to call Dispose() on my DbContext objects? Nope That said , I suggest that you use one context per method(and dispose...

Why does this code to replace accented chars with html codes fail to work?

c#,html,winforms,diacritics,accented-strings

Only thing I can think of is specifically specifying your encoding on the file write, like: File.WriteAllLines(massagedFileName, linesModified, Encoding.UTF8); ...

Connecting to database using Windows Athentication

sql-server,vb.net,authentication,connection-string

You need to add Integrated Security=SSPI and remove username and password from the connection string. Dim ConnectionString As String = "Data Source=Server;Initial Catalog=m2mdata02;Integrated Security=SSPI;" ...

Convert Double from String

asp.net,vb.net,visual-studio-2012,converter

The result isn't wrong, it only has lower precision than you expected. Floating point numbers have a limited precision by design, and you simply can't expect to get a result that is more precise than its limit. You can use a Decimal to get higher precision. In this case it...

check if a list contains all the element in an array using linq

vb.net,linq

You can use Enumerable.All: dim linqMeddata = From m In medicineDataList Where keys.All(Function(k) m.MedicineData.Contains(k)) Order By m.MedicineName Ascending Select m ...

Get List of Elements in Tree with specific Field Value

vb.net,linq,properties,interface

If i have understood it correctly you want to get all selected parents and all selected children. You could use a recursive method: Public ReadOnly Property checkedList As List(Of TreeSelectorAttributes) Get Return rootList.Where(Function(t) t.SelectedInTreeSelector). SelectMany(Function(root) GetSelectedChildren(root)). ToList() End Get End Property Function GetSelectedChildren(root As TreeSelectorAttributes, Optional includeRoot As Boolean =...

VB.Net DateTime conversion

jquery,vb.net,datetime

System.Globalization.DateTimeFormatInfo.InvariantInfo doesn't contain format pattern dd-MM-yyyy(26-06-2015) From MSDN about InvariantCulture The InvariantCulture property can be used to persist data in a culture-independent format. This provides a known format that does not change For using invariant format in converting string to DateTime your string value must be formatted with one of...

How to make existing forms deriven from a base form in VB.net

vb.net,inheritance

Since you want to change existing forms to inherit another base class you need to change each form that you want to take effect and change what they inherit. Go to each of your forms designer code class. Inside towards the top you will see the inherits statment. Change what...

How do I use VB.NET to send an email from an Outlook account?

vb.net,email

change the smtpserver from smtp.outlook.com to smtp-mail.outlook.com web.config settings <mailSettings> <smtp deliveryMethod="Network" from="[email protected]"> <network host="smtp-mail.outlook.com" userName="[email protected]" password="passwordhere" port="587" enableSsl="true"/> </smtp> </mailSettings> ...

VBMath using / equivalent in C# [closed]

c#,vb.net

You need to add Microsoft.VisualBasic as a reference to your Project. In your Project in the Solution Explorer right-click References and select "Add Reference". Search for "Microsoft.VisualBasic" in the Framework Tab.