Jump to content

Tab control need to shorten the code


Recommended Posts

Hi Experts,

I know this is my second post of asking how to shorten my code, I just need to have it shortened for there are too many Q and A coming from our station and I don't want to create another Radio button and FileReadLine() just to create another entry under Tab control.:>

Honestly, the first post regarding on shortening my code is kind of hard for me to understand.:sweating:

Just want to share my bad week days, do you know the feeling that from your head asking you to provide a program ASAP which they don't even know how hard for us to create a program easily per requirements? Harsh days isn't it....:'( even a simple one won't come up to your mind.

But anyway, I have my compiled code below and that's the result of so many tasks and couldn't even think how to shorten this on my own.:(

#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
$file = "D:\Programs\" & @UserName & "\Test.ini"
Func XPStyle($theme = 0)
    If Not StringInStr(@OSTYPE, "WIN32_NT") Then Return 0

    If $theme = 0 Or Not IsArray($theme) Then
       $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
 EndFunc
 Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0]+2, $aTabPos[1]+23, $aTabPos[2]-4, $aTabPos[3]-26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc
Example()

Func Example()
    $Form1 = GUICreate("Form1", 600, 438, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(16, 24, 570, 380)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
    GUICtrlCreateTabItem("Tab 1")
    _GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 64, 280, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 79, 280, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 280, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 280, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 280, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 280, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 280, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 280, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 280, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 280, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 280, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 280, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 280, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 280, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 280, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()

GUICtrlCreateTabItem("Tab 2")
_GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 62, 80, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 78, 80, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 80, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 80, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 80, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 80, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 80, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 80, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 80, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 80, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 80, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 80, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 80, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 80, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 80, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()

GUICtrlCreateTabItem("Tab 3")
_GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 62, 80, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 78, 80, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 80, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 80, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 80, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 80, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 80, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 80, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 80, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 80, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 80, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 80, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 80, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 80, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 80, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()

GUICtrlCreateTabItem("Tab 4")
_GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 62, 80, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 78, 80, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 80, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 80, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 80, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 80, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 80, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 80, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 80, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 80, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 80, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 80, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 80, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 80, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 80, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()

GUICtrlCreateTabItem("Tab 5")
_GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 62, 80, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 78, 80, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 80, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 80, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 80, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 80, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 80, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 80, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 80, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 80, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 80, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 80, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 80, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 80, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 80, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()

GUICtrlCreateTabItem("Tab 6")
_GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)
$Label1 = GUICtrlCreateLabel(FileReadLine($file, 1), 20, 50, 1000, 17)
$Radio1A = GUICtrlCreateRadio(FileReadLine($file, 2), 35, 62, 80, 15)
$Radio1B = GUICtrlCreateRadio(FileReadLine($file, 3), 35, 78, 80, 15)
$Radio1C = GUICtrlCreateRadio(FileReadLine($file, 4), 35, 94, 80, 15)
GUIStartGroup()
$Label2 = GUICtrlCreateLabel(FileReadLine($file, 5), 20, 120, 1000, 17)
$Radio2A = GUICtrlCreateRadio(FileReadLine($file, 6), 35, 135, 80, 15)
$Radio2B = GUICtrlCreateRadio(FileReadLine($file, 7), 35, 151, 80, 15)
$Radio2C = GUICtrlCreateRadio(FileReadLine($file, 8), 35, 167, 80, 15)
GUIStartGroup()
$Label3 = GUICtrlCreateLabel(FileReadLine($file, 9), 20, 195, 1000, 17)
$Radio3A = GUICtrlCreateRadio(FileReadLine($file, 10), 35, 210, 80, 15)
$Radio3B = GUICtrlCreateRadio(FileReadLine($file, 11), 35, 225, 80, 15)
$Radio3C = GUICtrlCreateRadio(FileReadLine($file, 12), 35, 240, 80, 15)
GUIStartGroup()
$Label4 = GUICtrlCreateLabel(FileReadLine($file, 13), 20, 268, 1000, 17)
$Radio4A = GUICtrlCreateRadio(FileReadLine($file, 14), 35, 280, 80, 15)
$Radio4B = GUICtrlCreateRadio(FileReadLine($file, 15), 35, 295, 80, 15)
$Radio4C = GUICtrlCreateRadio(FileReadLine($file, 16), 35, 310, 80, 15)
GUIStartGroup()
$Label5 = GUICtrlCreateLabel(FileReadLine($file, 17), 20, 335, 1000, 17)
$Radio5A = GUICtrlCreateRadio(FileReadLine($file, 18), 35, 350, 80, 15)
$Radio5B = GUICtrlCreateRadio(FileReadLine($file, 19), 35, 365, 80, 15)
$Radio5C = GUICtrlCreateRadio(FileReadLine($file, 20), 35, 380, 80, 15)
GUIStartGroup()

$Label6 = GUICtrlCreateLabel(FileReadLine($file, 21), 350, 50, 1000, 17)
$Radio6A = GUICtrlCreateRadio(FileReadLine($file, 22), 370, 62, 80, 15)
$Radio6B = GUICtrlCreateRadio(FileReadLine($file, 23), 370, 78, 80, 15)
$Radio6C = GUICtrlCreateRadio(FileReadLine($file, 24), 370, 94, 80, 15)
GUIStartGroup()
$Label7 = GUICtrlCreateLabel(FileReadLine($file, 25), 350, 120, 1000, 17)
$Radio7A = GUICtrlCreateRadio(FileReadLine($file, 26), 370, 135, 80, 15)
$Radio7B = GUICtrlCreateRadio(FileReadLine($file, 27), 370, 151, 80, 15)
$Radio7C = GUICtrlCreateRadio(FileReadLine($file, 28), 370, 167, 80, 15)
GUIStartGroup()
$Label8 = GUICtrlCreateLabel(FileReadLine($file, 29), 350, 195, 1000, 17)
$Radio8A = GUICtrlCreateRadio(FileReadLine($file, 30), 370, 210, 80, 15)
$Radio8B = GUICtrlCreateRadio(FileReadLine($file, 31), 370, 225, 80, 15)
$Radio8C = GUICtrlCreateRadio(FileReadLine($file, 32), 370, 240, 80, 15)
GUIStartGroup()
$Label9 = GUICtrlCreateLabel(FileReadLine($file, 33), 350, 268, 1000, 17)
$Radio9A = GUICtrlCreateRadio(FileReadLine($file, 34), 370, 280, 80, 15)
$Radio9B = GUICtrlCreateRadio(FileReadLine($file, 35), 370, 295, 80, 15)
$Radio9C = GUICtrlCreateRadio(FileReadLine($file, 36), 370, 310, 80, 15)
GUIStartGroup()
$Label10 = GUICtrlCreateLabel(FileReadLine($file, 37), 350, 335, 1000, 17)
$Radio10A = GUICtrlCreateRadio(FileReadLine($file, 38), 370, 350, 80, 15)
$Radio10B = GUICtrlCreateRadio(FileReadLine($file, 39), 370, 365, 80, 15)
$Radio10C = GUICtrlCreateRadio(FileReadLine($file, 40), 370, 380, 80, 15)
GUIStartGroup()
GUISetState(@SW_SHOW)
    While 1
        $idMsg = GUIGetMsg()

        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

Would gladly appreciate for the help Experts.

 

Thanks!

KS15

Test.ini

Edited by KickStarter15
Edit: Attaching sample Test.ini

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

This script has two alternative For-Next loops to use.    To use the second For-Next loop,  un-comment  (remove the  leading semicolon on) the two lines starting ":#cs ;------" and ":#ce;------". This will block comment all lines between "#cs"  and "#ce". 

Then, to use the following loop, add semicolon in front of the "#cs"  and "#ce" that are around the following loop so that they look like ":#cs " and ":#ce".   This will remove the block comment around the following For-Next loop and will be ready to use.

;#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>

$file = "Test.ini" ;"D:\Programs\" & @UserName & "\Test.ini"
Example()


Func XPStyle($theme = 0)
    If Not StringInStr(@OSType, "WIN32_NT") Then Return 0
    If $theme = 0 Or Not IsArray($theme) Then
        $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
EndFunc   ;==>XPStyle

Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc   ;==>_GUICtrlTabSetBkColor

Func Example()
    $Form1 = GUICreate("Form1", 600, 438, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(16, 24, 570, 380)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    $iFileLineNo = 1
    $iTotalTabs = 14  ; < ----------------------------Enter number of tabs required.
    Local $Radio[30 * $iTotalTabs+ 1] = [30 * $iTotalTabs] ; Array to store the id's of the 30 radio buttons from each of the 6 tabs when created.

    For $b = 0 To $iTotalTabs - 1 ; Tabs loop
        GUICtrlCreateTabItem("Tab " & $b + 1)
        _GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)

        ;#cs ;----------------Use either this For-Next loop or the following For-Next loop ------------------------
        For $a = 0 To 9 ; 10 groups of a label and 3 radio buttons on each tab.
            $Label1 = GUICtrlCreateLabel($a + 1 & ". Question " & ($b * 10) + $a + 1, 20 + (Int($a / 5) * 330), 50 + (70 * Mod($a, 5)), 200, 17) ; FileReadLine($file, $iFileLineNo)
            $Radio[($a * 3) + 1 + ($b * 30)] = GUICtrlCreateRadio("A. Answer 1", 35 + (Int($a / 5) * 330), 64 + ((70) * Mod($a, 5)), 200, 18)
            $Radio[($a * 3) + 2 + ($b * 30)] = GUICtrlCreateRadio("B. Answer 2", 35 + (Int($a / 5) * 330), 79 + ((70) * Mod($a, 5)), 200, 18)
            $Radio[($a * 3) + 3 + ($b * 30)] = GUICtrlCreateRadio("C. Answer 3", 35 + (Int($a / 5) * 330), 94 + ((70) * Mod($a, 5)), 200, 18)
            GUIStartGroup()
        Next
        ;#ce ;------------------------------------------------------------------------------------------------
        ;Or
        #cs  ;----------------- This is the following For-Next loop for use with ini file. -------------------
        For $a = 0 To 9 ; 10 groups of a label and 3 radio buttons on each tab.
            $Label1 = GUICtrlCreateLabel(FileReadLine($file, $iFileLineNo), 20 + (Int($a / 5) * 330), 50 + (70 * Mod($a, 5)), 200, 17) ; FileReadLine($file, $iFileLineNo)
            $iFileLineNo += 1
            $Radio[($a * 3) + 1 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 64 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            $Radio[($a * 3) + 2 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 79 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            $Radio[($a * 3) + 3 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 94 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            GUIStartGroup()
        Next
        #ce  ;------------------------------------------------------------------------------------------------
    Next
    ;_ArrayDisplay($Radio)

    GUISetState(@SW_SHOW)
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

 

Link to comment
Share on other sites

@Malkey, Thank you so much for the code appreciated and perfectly working, however, the word ". Question" and "Answer" was stated already in the code. Is there a way that we will follow what was added in Test.ini? like for example in test.ini I have this question "1. How long you've been using AutoIt?" and the answer part are "A. One year; B. Two years; C. Three years".^_^

For $a = 0 To 9 ; 10 groups of a label and 3 radio buttons on each tab.
            $Label1 = GUICtrlCreateLabel($a + 1 & ". Question " & ($b * 10) + $a + 1, 20 + (Int($a / 5) * 330), 50 + (70 * Mod($a, 5)), 200, 17) ; FileReadLine($file, $iFileLineNo)
            $Radio[($a * 3) + 1 + ($b * 30)] = GUICtrlCreateRadio("A. Answer 1", 35 + (Int($a / 5) * 330), 64 + ((70) * Mod($a, 5)), 200, 18)
            $Radio[($a * 3) + 2 + ($b * 30)] = GUICtrlCreateRadio("B. Answer 2", 35 + (Int($a / 5) * 330), 79 + ((70) * Mod($a, 5)), 200, 18)
            $Radio[($a * 3) + 3 + ($b * 30)] = GUICtrlCreateRadio("C. Answer 3", 35 + (Int($a / 5) * 330), 94 + ((70) * Mod($a, 5)), 200, 18)
            GUIStartGroup()
        Next

 

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Using your "Test.ini" file from post #1, and this "TestCorrectAns.ini" file:-

1-A
2-B
3-C
4-C
5-B
6-C
7-A
8-A
9-C
10-B

This example will get and check the answers entered with the above correct answers file and put the number correct in first element of the $aAnswers array.  With the _FileWriteFromArray() function (see AutoIt help) the  $aAnswers array could be used to write the array to a file for a more permanent record of the results.

Press "Ctrl+Alt+r", the hot key to activate the _GetCheckAnswers() function in the script. (Remember to check some radio buttons first)

;#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>

HotKeySet("^!r", "_GetCheckAnswers") ; Ctrl+Alt+r
Global $file = "Test.ini" ;"D:\Programs\" & @UserName & "\Test.ini"
Example()


Func XPStyle($theme = 0)
    If Not StringInStr(@OSType, "WIN32_NT") Then Return 0
    If $theme = 0 Or Not IsArray($theme) Then
        $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
EndFunc   ;==>XPStyle

Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc   ;==>_GUICtrlTabSetBkColor

Func Example()
    $Form1 = GUICreate("Form1", 600, 438, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(16, 24, 570, 380)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    $iFileLineNo = 1
    $iTotalTabs = 2 ; < ----------------------------Enter number of tabs required.
    Global $Radio[30 * $iTotalTabs] ; Array to store the id's of the 30 radio buttons from each of the 6 tabs when created.

    For $b = 0 To $iTotalTabs - 1 ; Tabs loop
        GUICtrlCreateTabItem("Tab " & $b + 1)
        _GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)

        For $a = 0 To 9 ; 10 groups of a label and 3 radio buttons on each tab.
            $Label1 = GUICtrlCreateLabel(FileReadLine($file, $iFileLineNo), 20 + (Int($a / 5) * 330), 50 + (70 * Mod($a, 5)), 200, 17) ; FileReadLine($file, $iFileLineNo)
            $iFileLineNo += 1
            $Radio[($a * 3) + 0 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 64 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            $Radio[($a * 3) + 1 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 79 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            $Radio[($a * 3) + 2 + ($b * 30)] = GUICtrlCreateRadio(FileReadLine($file, $iFileLineNo), 35 + (Int($a / 5) * 330), 94 + ((70) * Mod($a, 5)), 200, 18)
            $iFileLineNo += 1
            GUIStartGroup()
        Next
    Next
    ;_ArrayDisplay($Radio)

    GUISetState(@SW_SHOW)
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

Func _GetCheckAnswers()
    $aRes = FileReadToArray("TestCorrectAns.ini")
    Global $aAnswers[UBound($aRes) + 1]
    Local $iSumCorr = 0
    For $i = 0 To UBound($Radio) - 3 Step 3
        If Int($i / 3) >= UBound($aRes) Then ExitLoop
        If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then $aAnswers[Int($i / 3) + 1] = (Int($i / 3) + 1) & "-A"
        If BitAND(GUICtrlRead($Radio[$i + 1]), $GUI_CHECKED) = $GUI_CHECKED Then $aAnswers[Int($i / 3) + 1] = (Int($i / 3) + 1) & "-B"
        If BitAND(GUICtrlRead($Radio[$i + 2]), $GUI_CHECKED) = $GUI_CHECKED Then $aAnswers[Int($i / 3) + 1] = (Int($i / 3) + 1) & "-C"

        If $aAnswers[Int($i / 3) + 1] == $aRes[Int($i / 3)] Then
            $aAnswers[Int($i / 3) + 1] &= " Correct"
            $iSumCorr += 1
        ElseIf $aAnswers[Int($i / 3) + 1] == "" Then
            $aAnswers[Int($i / 3) + 1] = (Int($i / 3) + 1) & "-Not Answered"
        EndIf
    Next
    $aAnswers[0] = $iSumCorr ; Total number correct in $aAnswers[0]
    _ArrayDisplay($aAnswers, "Results")
EndFunc   ;==>_GetCheckAnswers

 

Edited by Malkey
$iFileLineNo = 1 not 0, and, prettied up $aAnswers array.
Link to comment
Share on other sites

Added some features:-
- A two lined question will now fit;
- Variable number of answers allowed. (max. 5. A to E);
- The number of questions governs the number of tab created.  10 questions per tab.  So for 12 questions there will be 10 questions on the first tab and 2 questions on the next tab;
- To uncheck the checked button in a group of radio buttons, hover the cursor over the checked radio button then press keys "Ctrl"+"Alt"+"u".    The results will show for this question "-Not Answered";
- As in the previous example   "Ctrl"+"Alt"+"r" gets and checks the results.  The number correct is in the 1st element of the $aAnswers array.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPI.au3>
; https://www.autoitscript.com/forum/topic/189195-tab-control-need-to-shorten-the-code/

HotKeySet("^!r", "_GetCheckAnswers") ; Ctrl+Alt+r
HotKeySet("^!u", "_UnCheckRadio") ; Have the cursor hover over the radio button you want unchecked then press Ctrl+Alt+u

Global $sFileCorrAns = "TestCorrectAns.ini" ; File with correct Answers
Global $file = "Test.ini" ;"D:\Programs\" & @UserName & "\Test.ini" ; File with Question and Answers
Example()


Func Example()
    $Form1 = GUICreate("Form1", 680, 620, 230, 150, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(16, 24, 650, 580)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    Global $aQA2D = _FileTo2D($file)
    $iFileLineNo = 0
    $iTotalTabs = Ceiling(UBound($aQA2D) / 10)
    Global $Radio[60 * $iTotalTabs] ; Array to store the id's of the 10 questions per tabs max of 5 answers per question making 60 elements per tabs.

    For $b = 0 To $iTotalTabs - 1 ; Tabs loop
        GUICtrlCreateTabItem("Tab " & $b + 1)
        _GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)

        For $a = 0 To 9 ; 10 groups of a label and 3 radio buttons on each tab.
            If $a + ($b * 10) >= UBound($aQA2D) Then ExitLoop
            $Label1 = GUICtrlCreateLabel($aQA2D[$a + ($b * 10)][0], 20 + (Int($a / 5) * 330), 50 + (110 * Mod($a, 5)), 310, 32) ; FileReadLine($file, $iFileLineNo)
            $Radio[$iFileLineNo] = "Q" & (1 + $a + ($b * 10)) & "Next " & $aQA2D[$a + ($b * 10)][1]
            $iFileLineNo += 1
            For $c = 2 To $aQA2D[$a + ($b * 10)][1] + 1
                ;ConsoleWrite($a + ($b * 10) & "  " & $c & @CRLF)
                $Radio[$iFileLineNo] = GUICtrlCreateRadio($aQA2D[$a + ($b * 10)][$c], 35 + (Int($a / 5) * 330), 80 + (($c - 2) * 15) + ((110) * Mod($a, 5)), 300, 18)
                $iFileLineNo += 1
            Next
            GUIStartGroup()
        Next
    Next
    ReDim $Radio[$iFileLineNo]
    ;_ArrayDisplay($Radio)

    GUISetState(@SW_SHOW)
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

Func _GetCheckAnswers()
    $aRes = FileReadToArray($sFileCorrAns)
    ;_ArrayDisplay($aRes, "Correct Answers")
    Global $aAnswers[UBound($aQA2D) + 1]
    $iAnsIndex = 1
    Local $iSumCorr = 0
    For $i = 0 To UBound($Radio) - 1
        $iNumAns = StringRegExpReplace($Radio[$i], "^Q\d+Next ", "")
        $iQuesNum = StringRegExpReplace($Radio[$i], "^Q|Next \d+", "")
        For $j = 0 To $iNumAns - 1
            $i += 1
            If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                $aAnswers[$iAnsIndex] = $iQuesNum & "-" & ChrW(65 + $j) ; ChrW(65) = "A"
            EndIf
            If $aAnswers[$iAnsIndex] == $aRes[$iAnsIndex - 1] Then ; $aRes[$iAnsIndex - 1] because $aAnswers array will have $iSumCorr in 1st element.
                $aAnswers[$iAnsIndex] &= " Correct"
                $iSumCorr += 1
            ElseIf $aAnswers[$iAnsIndex] == "" Then
                $aAnswers[$iAnsIndex] = $iQuesNum & "-Not Answered"
            EndIf
        Next
        $iAnsIndex += 1
    Next
    $aAnswers[0] = $iSumCorr ; Total number correct in $aAnswers[0]
    _ArrayDisplay($aAnswers, "Results")
EndFunc   ;==>_GetCheckAnswers

#cs Example in file"-
    1.Question 1
    A.Answer 1
    B.Answer 2
    C.Answer 3
    2.Question 2
    A.Answer 1
    B.Answer 2
    C.Answer 3
    D.Answer 4
    E.Answer 5
    ....
    Example returned 2D array:-
    1.Question 1|3|A.Answer 1|B.Answer 2|C.Answer 3||
    2.Question 2|5|A.Answer 1|B.Answer 2|C.Answer 3|D.Answer 4|E.Answer 5
    ....
    The return 2D array has:-
    $a2DArray[n][0] contains Question n+1;
    $a2DArray[n][1] contains the number of anawers (max 5 answers);
    $a2DArray[n][2 to 6] contains the answers;
    where n+1 is the number of questions, or, n is the array's index starting at 0.
#ce
Func _FileTo2D($sFileName)
    Local $i
    Local $iCount = 0 ; 2D array row index - one question with answers  on each row.
    Local $iAnsCount = 0 ; Counts number of answers to each question - Total stored in 2nd column element of 2D array.
    Local $iIndexAns = 2 ; 2D array column index where to store the answers.
    $aQA = FileReadToArray($sFileName)
    Local $aQA2D[UBound($aQA)][7]
    For $i = 0 To UBound($aQA) - 1
        $aQA2D[$iCount][0] = $aQA[$i] ; Enter Question into 1st element of 2D array.
        $i += 1
        While (StringInStr($aQA[$i], "Question", 1) = 0)
            $aQA2D[$iCount][$iIndexAns] = $aQA[$i] ; Enter Answes into 2D array starting at column index 2.
            $i += 1
            $iAnsCount += 1
            $iIndexAns += 1
            If $i = UBound($aQA) Then ExitLoop
            ;ConsoleWrite($i &  "  " & StringInStr($aQA[$i], "Answer") &  "  " & $iCount &  "  " & $iIndexAns & @CRLF)
            ;_ArrayDisplay($aQA2D)
        WEnd
        $iIndexAns = 2
        $aQA2D[$iCount][1] = $iAnsCount ; Enter number of Answers into 2nd element of 2D array.
        $iCount += 1
        $iAnsCount = 0
        $i -= 1
    Next
    ReDim $aQA2D[$iCount][7]
    Return $aQA2D
EndFunc   ;==>_FileTo2D

Func XPStyle($theme = 0)
    If Not StringInStr(@OSType, "WIN32_NT") Then Return 0
    If $theme = 0 Or Not IsArray($theme) Then
        $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
EndFunc   ;==>XPStyle

Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc   ;==>_GUICtrlTabSetBkColor

Func _UnCheckRadio()
    $tPoint = _WinAPI_GetMousePos()
    $hWnd = _WinAPI_WindowFromPoint($tPoint)
    GUICtrlSetState(_WinAPI_GetDlgCtrlID($hWnd), 4) ; $GUI_UNCHECKED (4)
EndFunc   ;==>_UnCheckRadio

 

"Test.ini" file used:-

1.Question 1  A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answer 1
B.Answer 2
C.Answer 3
2.Question 2
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
3.Question 3
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
4.Question 4
A.Answere 1
B.Answere 2
C.Answere 3
5.Question 5
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
6.Question 6  A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answere 1
B.Answere 2
C.Answere 3
7.Question 7
A.Answere 1
B.Answere 2
C.Answere 3
D.Answere 4
8.Question 8
A.Answere 1
B.Answere 2
C.Answere 3
9.Question 9
A.Answere 1
B.Answere 2
C.Answere 3
10.Question 10
A.Answere 1
B.Answere 2
C.Answere 3
1.Question 11
A.Answere 1
B.Answere 2
C.Answere 3
2.Question 12
A.Answere 1
B.Answere 2
C.Answere 3

 

"TestCorrectAns.ini" file used:-

1-A
2-D
3-E
4-C
5-B
6-C
7-A
8-A
9-C
10-B
11-A
12-C

 

Link to comment
Share on other sites

@Malkey,

Sorry for the late reply, I was on leave for vacation. Anyway, thanks for enhancing the code, I'm a little bit shuffled with the code on how did you do it (having hard time to understand so far :sweating:) but as what I've tested, still has an issue in handling the code.

1. In "Test.ini", Do I need to add the word "Question" in every item of question? The code won't work if there is no word "Question" from the start.

1. How long you've been using AutoIt?
A. One year
B. Two year
C. Three year
2. Question How many units of PCs in every station?
A. Ten
B. Twenty
C. Thirty
3. Question AutoIt is the best?
A. Yes
B. Yes
C. Yes
....

2. In every TAB, it has different category and separate ".ini" file where the questions and answers were stored. So having it the way you've suggested may not be advisable to follow.

19 hours ago, Malkey said:

So for 12 questions there will be 10 questions on the first tab and 2 questions on the next tab;

3. Each tab will also have there own tab name like for example in tab 1 will be named as "First process" and for tab 2 "Front process" until the end of the categories we have. Is there a way to have it? and I could not do it doing the below code you have.:>

GUICtrlCreateTabItem("Tab " & $b + 1)

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Addressing your queries:-
1. As each question starts with a digit, on line #114 in the _FileTo2D() function replace

"While (StringInStr($aQA[$i], "Question", 1) = 0)"

with

While (StringRegExp($aQA[$i], "^\d+") = 0) ; <--- Questions start with a digit. So, if 1st character in line is not a digit then continue loop.

2.  Do you envisage a max. of 10 questions per tab (per different category) and no more?
If more than ten  questions per tab then maybe scrollbars can be used. See this example.

3. Would it be possible to put the tab name on the first line of the ini file that is to be used for that particular tab?
That would make it easy to get the tab name into the GUICtrlCreateTabItem() function.

Link to comment
Share on other sites

@Malkey,

For item 1, greatly worked and thank you.^_^

2. I assume we only have 10 questions per tab as this was the agreement we had with the heads. If in case, then I'll use the scrollbars sample you've provided. Thanks!

3. Yes, I can include that in .ini for us to make it easier. Let's say, first tab name then questions and answers after the 10th Q and A, second tab will follow etc...

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Added features:-
- Each Q and A file is displayed on a separate tabs up to a maximum of ten questions per tab;
- Each Q and A file has to have an accompanying correct answer file;
- Each time "Ctrl"+"Alt"+"r" is pressed the file "Results.csv" is created in the script directory from the $aAnswers array @ approx. line #85.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPI.au3>
; https://www.autoitscript.com/forum/topic/189195-tab-control-need-to-shorten-the-code/

HotKeySet("^!r", "_GetCheckAnswers") ; Ctrl+Alt+r
HotKeySet("^!u", "_UnCheckRadio") ; Have the cursor hover over the radio button you want unchecked then press Ctrl+Alt+u

Global $sFileCorrAns[2] = ["TestCorrectAns.ini", "TestCorrectAnsTab2.ini"] ; Array of files with correct Answers.
Global $file[2] = ["Test.ini", "TestTab2.ini"] ; Array of files with Question and Answers.
Example()


Func Example()
    $Form1 = GUICreate("Form1", 680, 620, 230, 150, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(16, 24, 650, 580)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    Global $Radio[60][UBound($file)] ; Array to store the id's of the 10 questions per tabs max of 1 label + 5 answers per question making 60 elements per tabs.
    For $b = 0 To UBound($file) - 1 ; Tabs loop
        Global $aQA2D = _FileTo2D($file[$b])
        ;_ArrayDisplay($aQA2D, "$aQA2D")
        $iFileLineNo = 0

        GUICtrlCreateTabItem($aQA2D[0][0])
        _GUICtrlTabSetBkColor($Form1, $Tab1, 0xAACCFF)

        For $a = 1 To 10 ; 10 groups of a label(question)and $iFileLineNo radio buttons on each tab.
            If $a >= UBound($aQA2D) Then ExitLoop
            $Label1 = GUICtrlCreateLabel($aQA2D[$a][0], 20 + (Int(($a - 1) / 5) * 330), 50 + (110 * Mod($a - 1, 5)), 310, 32) ; FileReadLine($file, $iFileLineNo)
            $Radio[$iFileLineNo][$b] = "Q" & ($a) & "Next " & $aQA2D[$a][1]
            $iFileLineNo += 1
            ConsoleWrite($aQA2D[$a][1] & @CRLF)
            For $c = 2 To $aQA2D[$a][1] + 1
                ;ConsoleWrite($a + ($b * 10) & "  " & $c & @CRLF)
                $Radio[$iFileLineNo][$b] = GUICtrlCreateRadio($aQA2D[$a][$c], 35 + (Int(($a - 1) / 5) * 330), 80 + (($c - 2) * 15) + ((110) * Mod($a - 1, 5)), 300, 18)
                $iFileLineNo += 1
            Next
            GUIStartGroup()
        Next
    Next
    ;ReDim $Radio[$iFileLineNo]
    ;_ArrayDisplay($Radio)

    GUISetState(@SW_SHOW)
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

Func _GetCheckAnswers()
    Global $aAnswers[12][UBound($sFileCorrAns)]
    For $k = 0 To UBound($sFileCorrAns) - 1
        $aRes = FileReadToArray($sFileCorrAns[$k])
        $aAnswers[1][$k] = $aRes[0]
        ;_ArrayDisplay($aRes, "Correct Answers")
        ;_ArrayDisplay($aAnswers)
        $iAnsIndex = 2
        Local $iSumCorr = 0
        For $i = 0 To UBound($Radio) - 1 ; UBound($Radio) is max. 60 of one label plus 5 radio button *10 questions = 60
            If $Radio[$i][$k] = "" Then ExitLoop ; Instead of ReDim this allows Array columns of different lengths in $Radio array.
            $iNumAns = StringRegExpReplace($Radio[$i][$k], "^Q\d+Next ", "")
            $iQuesNum = StringRegExpReplace($Radio[$i][$k], "^Q|Next \d+", "")
            For $j = 0 To $iNumAns - 1
                $i += 1
                If BitAND(GUICtrlRead($Radio[$i][$k]), $GUI_CHECKED) = $GUI_CHECKED Then
                    $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-" & ChrW(65 + $j) ; ChrW(65) = "A"
                EndIf
                If $aAnswers[$iAnsIndex][$k] == $aRes[$iAnsIndex - 1] Then ; $aRes[$iAnsIndex - 1] because $aAnswers array will have $iSumCorr in 1st element.
                    $aAnswers[$iAnsIndex][$k] &= " Correct"
                    $iSumCorr += 1
                ElseIf $aAnswers[$iAnsIndex][$k] == "" Then
                    $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-Not Answered"
                EndIf
            Next
            $iAnsIndex += 1
        Next
        $aAnswers[0][$k] = $iSumCorr ; Total number correct in $aAnswers[0]
    Next
    _FileWriteFromArray("Results.csv", $aAnswers, Default, Default, ",")
    _ArrayDisplay($aAnswers, "Results")
EndFunc   ;==>_GetCheckAnswers

#cs ; _FileTo2D($sFileName) function takes a file and returns a 2D array.
    Example in file"-
    Tab Label
    1.Question 1
    A.Answer 1
    B.Answer 2
    C.Answer 3
    2.Question 2
    A.Answer 1
    B.Answer 2
    C.Answer 3
    D.Answer 4
    E.Answer 5
    ....
    Example returned 2D array:-
    Tab Label||||||
    1.Question 1|3|A.Answer 1|B.Answer 2|C.Answer 3||
    2.Question 2|5|A.Answer 1|B.Answer 2|C.Answer 3|D.Answer 4|E.Answer 5
    ....
    The return 2D array has:-
    $a2DArray[0][0] contains the tab's label
    $a2DArray[n][0] contains Question n
    $a2DArray[n][1] contains the number of anawers (max 5 answers);
    $a2DArray[n][2 to 6 inndex] contains the answers;
    $a2DArray[n + 1][0] contains Question n+1;
    $a2DArray[n + 1][1] contains the number of anawers to Question n+1;
    ....
    ; where n is the question number, or, array index.
#ce
Func _FileTo2D($sFileName)
    Local $i
    Local $iCount = 0 ; 2D array row index - one question with answers  on each row.
    Local $iAnsCount = 0 ; Counts number of answers to each question - Total stored in 2nd column element of 2D array.
    Local $iIndexAns = 2 ; 2D array column index where to store the answers.
    $aQA = FileReadToArray($sFileName)
    ;_ArrayDisplay($aQA)
    Local $aQA2D[UBound($aQA)][7]
    $aQA2D[0][0] = $aQA[$iCount]
    $iCount += 1
    For $i = 1 To UBound($aQA) - 1
        $aQA2D[$iCount][0] = $aQA[$i] ; Enter Question into 1st element of 2D array.
        $i += 1
        ;While (StringInStr($aQA[$i], "Question", 1) = 0)
        While (StringRegExp($aQA[$i], "^\d+") = 0) ; <--- Questions start with a digit. So, if 1st character in line is not a digit then continue loop.
            $aQA2D[$iCount][$iIndexAns] = $aQA[$i] ; Enter Answes into 2D array starting at column index 2.
            $i += 1
            $iAnsCount += 1
            $iIndexAns += 1
            If $i = UBound($aQA) Then ExitLoop
            ;ConsoleWrite($i &  "  " & StringInStr($aQA[$i], "Answer") &  "  " & $iCount &  "  " & $iIndexAns & @CRLF)
            ;_ArrayDisplay($aQA2D)
        WEnd
        $iIndexAns = 2
        $aQA2D[$iCount][1] = $iAnsCount ; Enter number of Answers into 2nd element of 2D array.
        $iCount += 1
        $iAnsCount = 0
        $i -= 1
    Next
    ReDim $aQA2D[$iCount][7]
    Return $aQA2D
EndFunc   ;==>_FileTo2D

Func XPStyle($theme = 0)
    If Not StringInStr(@OSType, "WIN32_NT") Then Return 0
    If $theme = 0 Or Not IsArray($theme) Then
        $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
EndFunc   ;==>XPStyle

Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc   ;==>_GUICtrlTabSetBkColor

Func _UnCheckRadio()
    $tPoint = _WinAPI_GetMousePos()
    $hWnd = _WinAPI_WindowFromPoint($tPoint)
    GUICtrlSetState(_WinAPI_GetDlgCtrlID($hWnd), 4) ; $GUI_UNCHECKED (4)
EndFunc   ;==>_UnCheckRadio

 

The file "TestCorrectAns.ini" used is

First process
1-A
2-D
3-E
4-C
5-B
6-C
7-A
8-A

 

The file "TestCorrectAnsTab2.ini" used is

Second process
1-B
2-C
3-A
4-C
5-B
6-C
7-B
8-A
9-A
10-B

 

The file "Test.ini" used is

First process
1. A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answer 1
B.Answer 2
C.Answer 3
2.
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
3.Question 3
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
4.Question 4
A.Answere 1
B.Answere 2
C.Answere 3
5.Question 5
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
6.Question 6  A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answere 1
B.Answere 2
C.Answere 3
7.Question 7
A.Answere 1
B.Answere 2
C.Answere 3
D.Answere 4
8.Question 8
A.Answere 1
B.Answere 2
C.Answere 3

 

The file "TestTab2.ini" used is

Second process
1. A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
2.
A.Answer 1
B.Answer 2
C.Answer 3
3.Question 3
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
E.Answer 5
4.Question 4
A.Answere 1
B.Answere 2
C.Answere 3
5.Question 5
A.Answer 1
B.Answer 2
C.Answer 3
D.Answer 4
6.Question 6  A very long question that spreads over two lines so that the format of the tabs can be figured out.
A.Answere 1
B.Answere 2
C.Answere 3
7.Question 7
A.Answere 1
B.Answere 2
C.Answere 3
D.Answere 4
8.Question 8
A.Answere 1
B.Answere 2
C.Answere 3
D.Answer 4
E.Answer 5
9.Question 9
A.Answere 1
B.Answere 2
C.Answere 3
10.Question 10
A.Answere 1
B.Answere 2
C.Answere 3
D.Answer 4
E.Answer 5

 

Link to comment
Share on other sites

@Malkey,

You really rock, everything is perfect as expected. Thank you so much, your one of the best.:lol: From this point, I can now do as many Q and A. Thanks!

One more thing, Is the below code is the right one to change if incase I want to add new .ini or tab?:>

$path = "D:\Programs\" & @UserName & "\"
Global $file[4] = [$path & "Test.ini", $path & "TestTab2.ini", $path & "TestTab3.ini", $path & "TestTab4.ini"] ; Array of files with Question and Answers.

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

@KickStarter15
Yes, your code of post #10 will show four  tabs, one file per tab.
Don't forget about the four accompanying "correct answers" files for the "Ctrl"+"Alt"+"r" hotkey to display results. Note, the file "Results.csv" that is generated with the display results can be imported into Excel or OpenOffice Calc.

$path = "D:\Programs\" & @UserName & "\"
Global $file[4] = [$path & "Test.ini", $path & "TestTab2.ini", $path & "TestTab3.ini", $path & "TestTab4.ini"] ; Array of files with Question and Answers.
; Path to the correct answers files could be a thumb drive.
Global $sFileCorrAns[4] = [$path & "TestCorrectAns.ini", $path & "TestCorrectAnsTab2.ini", $path & "TestCorrectAnsTab3.ini", $path & "TestCorrectAnsTab4.ini"]  ; Array of files with corresponding Correct Answers.


And here is another version with different coloured tabs and testing a third tab, "TestTab3.ini" and "TestCorrectAnsTab3.ini" with 17 questions. (files not included)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <GuiTab.au3>

#include <GUIScrollBars_Ex.au3> ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; "GUIScrollBars_Ex.au3" found @ https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-new-version-16-feb-17/
; ScrolBars Example https://www.autoitscript.com/forum/topic/125332-scrolling-problem/?do=findComment&comment=870352
; https://www.autoitscript.com/forum/topic/189195-tab-control-need-to-shorten-the-code/

HotKeySet("^!r", "_GetCheckAnswers") ; Ctrl+Alt+r
HotKeySet("^!u", "_UnCheckRadio") ; Have the cursor hover over the radio button you want unchecked then press Ctrl+Alt+u

; For testing:- "TestCorrectAns.ini" has 8 questions; "TestCorrectAnsTab2.ini" has 10 questions; and "TestCorrectAnsTab3.ini" has 17 questions.
Global $sFileCorrAns[3] = ["TestCorrectAns.ini", "TestCorrectAnsTab2.ini", "TestCorrectAnsTab3.ini"] ; Array of files with correct Answers.
Global $file[3] = ["Test.ini", "TestTab2.ini", "TestTab3.ini"] ; Array of files with Question and Answers.

QandAonTabs()


Func QandAonTabs()
    ; ---- Find largest number of questions on any tab ------
    Global $iNumofQues, $iNum
    For $i = 0 To UBound($sFileCorrAns) - 1
        $iNum = UBound(FileReadToArray($sFileCorrAns[$i])) - 1
        If $iNum > $iNumofQues Then $iNumofQues = $iNum
    Next
    ;ConsoleWrite("$iNumofQues = " & $iNumofQues & @CRLF)
    ; ---- End of Find largest number of questions on any tab ------

    ; <<<<<<<<<<< Calculate size of tab to accommodate the Questions and Answers.<<<<<<<<<<<<<<
    Global $w = 690, $h = ((Ceiling($iNumofQues / 2) * 7) + 2) * 16 ;$w = tab width, $h=(Number of buttons deep * 7 lines per question + 2 lines)* 16 pixels per line
    ConsoleWrite("$h  " & $h & @CRLF)
    ;<<<<<<<<<<<< End of Calculate size of tab to accommodate the Questions and Answers.<<<<<<<<

    $Form1 = GUICreate("Form1", $w + 10, 650, 230, 150, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
    $LastTheme = XPStyle()
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $Tab1 = GUICtrlCreateTab(5, 24, $w, $h, $TCS_BUTTONS)
    GUICtrlSetFont(-1, 10, 400)
    XPStyle($LastTheme)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    Global $Radio[($iNumofQues * 6)][UBound($file)] ; Array to store the id's of the $iNumofQues questions per tabs max of 1 label + 5 answers per question making 60 elements per tabs.
    Local $aColor[3] = [0xAAFFCC, 0xAACCFF, 0xFFAABB] ; 3 tab colours depending on $b value.

    For $b = 0 To UBound($file) - 1 ; Tabs loop
        Global $aQA2D = _FileTo2D($file[$b])
        ;_ArrayDisplay($aQA2D, "$aQA2D")
        $iFileLineNo = 0

        GUICtrlCreateTabItem($aQA2D[0][0])
        _GUICtrlTabSetBkColor($Form1, $Tab1, $aColor[Mod($b, UBound($aColor))])
        Local $iQuesinTab = UBound($aQA2D) - 1
        Local $iN = Ceiling($iQuesinTab / 2) ;  Number of Ques in tab height
        For $a = 1 To UBound($aQA2D) ;  groups of a label(question)and $iFileLineNo radio buttons on each tab.
            If $a >= UBound($aQA2D) Then ExitLoop
            $Label1 = GUICtrlCreateLabel($aQA2D[$a][0], 10 + (Int(($a - 1) / $iN) * 330), 50 + (110 * Mod($a - 1, $iN)), 325, 32) ; FileReadLine($file, $iFileLineNo)
            $Radio[$iFileLineNo][$b] = "Q" & ($a) & "Next " & $aQA2D[$a][1]
            $iFileLineNo += 1
            For $c = 2 To $aQA2D[$a][1] + 1
                $Radio[$iFileLineNo][$b] = GUICtrlCreateRadio($aQA2D[$a][$c], 35 + (Int(($a - 1) / $iN) * 330), 80 + (($c - 2) * 15) + ((110) * Mod($a - 1, $iN)), 300, 18)
                $iFileLineNo += 1
            Next
            GUIStartGroup()
        Next
    Next
    ;_ArrayDisplay($Radio)

    GUISetState(@SW_SHOW)

    ; Generate scrollbars
    _GUIScrollbars_Generate($Form1, $w, $h) ; This is all you need to do to get scrollbars <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>QandAonTabs

Func _GetCheckAnswers()
    Global $aAnswers[$iNumofQues + 2][UBound($sFileCorrAns)]
    For $k = 0 To UBound($sFileCorrAns) - 1
        $aRes = FileReadToArray($sFileCorrAns[$k])
        $aAnswers[1][$k] = $aRes[0]
        ;_ArrayDisplay($aRes, "Correct Answers")
        ;_ArrayDisplay($aAnswers)
        $iAnsIndex = 2
        Local $iSumCorr = 0
        For $i = 0 To UBound($Radio) - 1 ; UBound($Radio) is max. 60 of one label plus $iN radio button *10 questions = 60
            If $Radio[$i][$k] = "" Then ExitLoop ; Instead of ReDim this allows Array columns of different lengths in $Radio array.
            $iNumAns = StringRegExpReplace($Radio[$i][$k], "^Q\d+Next ", "")
            $iQuesNum = StringRegExpReplace($Radio[$i][$k], "^Q|Next \d+", "")
            For $j = 0 To $iNumAns - 1
                $i += 1
                If BitAND(GUICtrlRead($Radio[$i][$k]), $GUI_CHECKED) = $GUI_CHECKED Then
                    $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-" & ChrW(65 + $j) ; ChrW(65) = "A"
                EndIf
                If $aAnswers[$iAnsIndex][$k] == $aRes[$iAnsIndex - 1] Then ; $aRes[$iAnsIndex - 1] because $aAnswers array will have $iSumCorr in 1st element.
                    $aAnswers[$iAnsIndex][$k] &= " Correct"
                    $iSumCorr += 1
                ElseIf $aAnswers[$iAnsIndex][$k] == "" Then
                    $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-Not Answered"
                EndIf
            Next
            $iAnsIndex += 1
        Next
        $aAnswers[0][$k] = $iSumCorr ; Total number correct in $aAnswers[0]
    Next
    _FileWriteFromArray("Results.csv", $aAnswers, Default, Default, ",")
    _ArrayDisplay($aAnswers, "Results")
EndFunc   ;==>_GetCheckAnswers

#cs ; _FileTo2D($sFileName) function takes a file and returns a 2D array.
    Example in file"-
    Tab Label
    1.Question 1
    A.Answer 1
    B.Answer 2
    C.Answer 3
    2.Question 2
    A.Answer 1
    B.Answer 2
    C.Answer 3
    D.Answer 4
    E.Answer 5
    ....
    Example returned 2D array:-
    Tab Label||||||
    1.Question 1|3|A.Answer 1|B.Answer 2|C.Answer 3||
    2.Question 2|5|A.Answer 1|B.Answer 2|C.Answer 3|D.Answer 4|E.Answer 5
    ....
    The return 2D array has:-
    $a2DArray[0][0] contains the tab's label
    $a2DArray[n][0] contains Question n
    $a2DArray[n][1] contains the number of anawers (max 5 answers);
    $a2DArray[n][2 to 6 inndex] contains the answers;
    $a2DArray[n + 1][0] contains Question n+1;
    $a2DArray[n + 1][1] contains the number of anawers to Question n+1;
    ....
    ; where n is the question number, or, array index.
#ce
Func _FileTo2D($sFileName)
    Local $i
    Local $iCount = 0 ; 2D array row index - one question with answers  on each row.
    Local $iAnsCount = 0 ; Counts number of answers to each question - Total stored in 2nd column element of 2D array.
    Local $iIndexAns = 2 ; 2D array column index where to store the answers.
    $aQA = FileReadToArray($sFileName)
    ;_ArrayDisplay($aQA)
    Local $aQA2D[UBound($aQA)][7]
    $aQA2D[0][0] = $aQA[$iCount]
    $iCount += 1
    For $i = 1 To UBound($aQA) - 1
        $aQA2D[$iCount][0] = $aQA[$i] ; Enter Question into 1st element of 2D array.
        $i += 1
        ;While (StringInStr($aQA[$i], "Question", 1) = 0)
        While (StringRegExp($aQA[$i], "^\d+") = 0) ; <--- Questions start with a digit. So, if 1st character in line is not a digit then continue loop.
            $aQA2D[$iCount][$iIndexAns] = $aQA[$i] ; Enter Answes into 2D array starting at column index 2.
            $i += 1
            $iAnsCount += 1
            $iIndexAns += 1
            If $i = UBound($aQA) Then ExitLoop
            ;ConsoleWrite($i &  "  " & StringInStr($aQA[$i], "Answer") &  "  " & $iCount &  "  " & $iIndexAns & @CRLF)
            ;_ArrayDisplay($aQA2D)
        WEnd
        $iIndexAns = 2
        $aQA2D[$iCount][1] = $iAnsCount ; Enter number of Answers into 2nd element of 2D array.
        $iCount += 1
        $iAnsCount = 0
        $i -= 1
    Next
    ReDim $aQA2D[$iCount][7]
    Return $aQA2D
EndFunc   ;==>_FileTo2D

Func XPStyle($theme = 0)
    If Not StringInStr(@OSType, "WIN32_NT") Then Return 0
    If $theme = 0 Or Not IsArray($theme) Then
        $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return $theme
    ElseIf IsArray($theme) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0])
        Return $theme
    EndIf
    Return 0
EndFunc   ;==>XPStyle

Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor)
    ;Disabled Label to hold the color
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkColor)
EndFunc   ;==>_GUICtrlTabSetBkColor

Func _UnCheckRadio()
    $tPoint = _WinAPI_GetMousePos()
    $hWnd = _WinAPI_WindowFromPoint($tPoint)
    $iId = _WinAPI_GetDlgCtrlID($hWnd)
    ConsoleWrite(GUICtrlRead($iId) & @CRLF)
    GUICtrlSetState($iId, ((GUICtrlRead($iId) = 4) ? 1 : 4)) ; $GUI_UNCHECKED (4); $GUI_CHECKED (1)
EndFunc   ;==>_UnCheckRadio

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...