{"id":8303,"date":"2022-09-12T22:14:18","date_gmt":"2022-09-12T16:44:18","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/"},"modified":"2022-09-12T22:14:18","modified_gmt":"2022-09-12T16:44:18","slug":"solved-how-to-display-random-ques-from-text-file-in-vb","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/","title":{"rendered":"[Solved] How to display random ques from text file in vb?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-35825014\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"35825014\" data-parentid=\"35824752\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I would make a class &#8220;question&#8221; like this:<\/p>\n<pre><code>public Class Question\n\npublic questionas String\npublic answer1 as String\npublic answer2 as String\npublic answer3 as String\npublic answer4 as String\npublic correctAnswer as integer\n\npublic sub new(que as string, a1 as string, a2 as string, a3 as string, a4 as string, answer as integer)\n    question= que\n    answer1=a1\n    answer2=a2\n    answer3=a3\n    answer4=a4\n    correctAnswer=answer\nend sub\n\n\nend Class\n<\/code><\/pre>\n<p>Now load all your questions in the programm like this:<\/p>\n<pre><code>Imports System\nImports System.IO\n\nClass MainWindow\n    private listQuestions as List(Of Question)\n\nPublic Sub window_loaded() handles MainWindow.loaded\n    listQuestions = loadAllQuestions()        \nEnd Sub\n\n\n\nprivate function loadAllQuestions() as List(Of Question)\nDim str() As String\n    Try\n        ' Open the file using a stream reader.\n        Using sr As New StreamReader(\"example.txt\")\n            Dim line As String\n            ' Read the stream to a string and write the string to the console.\n\n            line = sr.ReadToEnd()\n            Str = line.Split(vbNewLine)\n        End Using\n    Catch e As Exception\n        Console.WriteLine(\"The file could not be read:\")\n        Console.WriteLine(e.Message)\n    End Try\n\n   'So now put the questions in your list:\n\n    dim list as new List(Of Question)\n\n    For i = 0 to str.count - 1\n        if (i+1) mod 5 = 0 then 'is divible without rest by 6\n           list.add(new Question(str(i-5), str(i-4), str(i-3), str(i-2), str(i-1), str(i))\n        end if\n\n    next\n\n    return list\n\n\n\nend sub\n\n'Load a random question:\nprivate sub btNext_click() handles btNext.click()\n    dim ranQuestion as Question\n\n    dim r as new random\n\n    ranQuestion = listFragen.item(r.next(0,listQuestions.count))\n\n\nEnd Class\n<\/code><\/pre>\n<p>Hope i could help you. To prevent that the programm can show the same question again its your job \ud83d\ude42<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to display random ques from text file in vb? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I would make a class &#8220;question&#8221; like this: public Class Question public questionas String public answer1 as String public answer2 as String public answer3 as String public answer4 as String public correctAnswer as integer public sub new(que as string, a1 as string, a2 as string, a3 as string, a4 as string, answer as integer) &#8230; <a title=\"[Solved] How to display random ques from text file in vb?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\" aria-label=\"More on [Solved] How to display random ques from text file in vb?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[2352,2353,353],"class_list":["post-8303","post","type-post","status-publish","format-standard","hentry","category-solved","tag-code-snippets","tag-randomaccessfile","tag-vb-net"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How to display random ques from text file in vb? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How to display random ques from text file in vb? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I would make a class &#8220;question&#8221; like this: public Class Question public questionas String public answer1 as String public answer2 as String public answer3 as String public answer4 as String public correctAnswer as integer public sub new(que as string, a1 as string, a2 as string, a3 as string, a4 as string, answer as integer) ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-12T16:44:18+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How to display random ques from text file in vb?\",\"datePublished\":\"2022-09-12T16:44:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\"},\"wordCount\":61,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"code-snippets\",\"randomaccessfile\",\"vb.net\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\",\"name\":\"[Solved] How to display random ques from text file in vb? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-12T16:44:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How to display random ques from text file in vb?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How to display random ques from text file in vb? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How to display random ques from text file in vb? - JassWeb","og_description":"[ad_1] I would make a class &#8220;question&#8221; like this: public Class Question public questionas String public answer1 as String public answer2 as String public answer3 as String public answer4 as String public correctAnswer as integer public sub new(que as string, a1 as string, a2 as string, a3 as string, a4 as string, answer as integer) ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/","og_site_name":"JassWeb","article_published_time":"2022-09-12T16:44:18+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How to display random ques from text file in vb?","datePublished":"2022-09-12T16:44:18+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/"},"wordCount":61,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["code-snippets","randomaccessfile","vb.net"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/","name":"[Solved] How to display random ques from text file in vb? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-12T16:44:18+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-display-random-ques-from-text-file-in-vb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How to display random ques from text file in vb?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=8303"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8303\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=8303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=8303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=8303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}