vb6parse 1.0.0

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
//! Properties for a `Data` control.
//!
//! This is used as an enum variant of
//! [`ControlKind::Data`](crate::language::controls::ControlKind::Data).
//! tag, name, and index are not included in this struct, but instead are part
//! of the parent [`Control`](crate::language::controls::Control) struct.
//!

use std::fmt::Display;
use std::str::FromStr;

use crate::errors::{FormError, ErrorKind};
use crate::files::common::Properties;
use crate::language::controls::{
    Activation, Align, Appearance, DragMode, MousePointer, OLEDropMode, TextDirection, Visibility,
};
use crate::language::Color;

use image::DynamicImage;
use num_enum::TryFromPrimitive;
use serde::Serialize;

/// Properties for a `Data` control.
///
/// This is used as an enum variant of
/// [`ControlKind::Data`](crate::language::controls::ControlKind::Data).
/// tag, name, and index are not included in this struct, but instead are part
/// of the parent [`Control`](crate::language::controls::Control) struct.
#[derive(Debug, PartialEq, Clone)]
pub struct DataProperties {
    /// A store for the properties of the Data control.
    pub align: Align,
    /// Appearance of the Data control.
    pub appearance: Appearance,
    /// Background color of the Data control.
    pub back_color: Color,
    /// Action to take when the BOF (Beginning of File) is reached.
    pub bof_action: BOFAction,
    /// Caption of the Data control.
    pub caption: String,
    /// Type of connection to the database.
    pub connection: ConnectionType,
    /// Name of the database to connect to.
    pub database_name: String,
    /// Default cursor type for the Data control.
    pub default_cursor_type: DefaultCursorType,
    /// Default type of data source for the Data control.
    pub default_type: DatabaseDriverType,
    /// Drag icon for the Data control.
    pub drag_icon: Option<DynamicImage>,
    /// Drag mode for the Data control.
    pub drag_mode: DragMode,
    /// Whether the Data control is enabled.
    pub enabled: Activation,
    /// Action to take when the EOF (End of File) is reached.
    pub eof_action: EOFAction,
    /// Whether the Data control is exclusive.
    pub exclusive: bool,
    /// Foreground color of the Data control.
    pub fore_color: Color,
    /// Height of the Data control.
    pub height: i32,
    /// Left position of the Data control.
    pub left: i32,
    /// Mouse icon for the Data control.
    pub mouse_icon: Option<DynamicImage>,
    /// Mouse pointer type for the Data control.
    pub mouse_pointer: MousePointer,
    /// Whether to negotiate the connection.
    pub negotiate: bool,
    /// OLE drop mode for the Data control.
    pub ole_drop_mode: OLEDropMode,
    /// Options for the Data control.
    pub options: i32,
    /// Whether the Data control is read-only.
    pub read_only: bool,
    /// Type of record set for the Data control.
    pub record_set_type: RecordSetType,
    /// Record source for the Data control.
    pub record_source: String,
    /// Text direction for the Data control.
    pub right_to_left: TextDirection,
    /// Tool tip text for the Data control.
    pub tool_tip_text: String,
    /// Top position of the Data control.
    pub top: i32,
    /// Visibility of the Data control.
    pub visible: Visibility,
    /// What's This Help ID for the Data control.
    pub whats_this_help_id: i32,
    /// Width of the Data control.
    pub width: i32,
}

impl Default for DataProperties {
    fn default() -> Self {
        DataProperties {
            align: Align::None,
            appearance: Appearance::ThreeD,
            back_color: Color::System { index: 5 },
            bof_action: BOFAction::MoveFirst,
            caption: String::new(),
            connection: ConnectionType::Access,
            database_name: String::new(),
            default_cursor_type: DefaultCursorType::Default,
            default_type: DatabaseDriverType::UseJet,
            drag_icon: None,
            drag_mode: DragMode::Manual,
            enabled: Activation::Enabled,
            eof_action: EOFAction::MoveLast,
            exclusive: false,
            fore_color: Color::System { index: 8 },
            height: 1215,
            left: 480,
            mouse_icon: None,
            mouse_pointer: MousePointer::Default,
            negotiate: false,
            ole_drop_mode: OLEDropMode::default(),
            options: 0,
            read_only: false,
            record_set_type: RecordSetType::Dynaset,
            record_source: String::new(),
            right_to_left: TextDirection::LeftToRight,
            tool_tip_text: String::new(),
            top: 840,
            visible: Visibility::Visible,
            whats_this_help_id: 0,
            width: 1140,
        }
    }
}

impl Serialize for DataProperties {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        use serde::ser::SerializeStruct;

        let mut s = serializer.serialize_struct("DataProperties", 30)?;
        s.serialize_field("align", &self.align)?;
        s.serialize_field("appearance", &self.appearance)?;
        s.serialize_field("back_color", &self.back_color)?;
        s.serialize_field("bof_action", &self.bof_action)?;
        s.serialize_field("caption", &self.caption)?;
        s.serialize_field("connection", &self.connection)?;
        s.serialize_field("database_name", &self.database_name)?;
        s.serialize_field("default_cursor_type", &self.default_cursor_type)?;
        s.serialize_field("default_type", &self.default_type)?;

        let option_text = self.drag_icon.as_ref().map(|_| "Some(DynamicImage)");

        s.serialize_field("drag_icon", &option_text)?;
        s.serialize_field("drag_mode", &self.drag_mode)?;
        s.serialize_field("enabled", &self.enabled)?;
        s.serialize_field("eof_action", &self.eof_action)?;
        s.serialize_field("exclusive", &self.exclusive)?;
        s.serialize_field("fore_color", &self.fore_color)?;
        s.serialize_field("height", &self.height)?;
        s.serialize_field("left", &self.left)?;

        let option_text = self.mouse_icon.as_ref().map(|_| "Some(DynamicImage)");

        s.serialize_field("mouse_icon", &option_text)?;
        s.serialize_field("mouse_pointer", &self.mouse_pointer)?;
        s.serialize_field("negotiate", &self.negotiate)?;
        s.serialize_field("ole_drop_mode", &self.ole_drop_mode)?;
        s.serialize_field("options", &self.options)?;
        s.serialize_field("read_only", &self.read_only)?;
        s.serialize_field("record_set_type", &self.record_set_type)?;
        s.serialize_field("record_source", &self.record_source)?;
        s.serialize_field("right_to_left", &self.right_to_left)?;
        s.serialize_field("tool_tip_text", &self.tool_tip_text)?;
        s.serialize_field("top", &self.top)?;
        s.serialize_field("visible", &self.visible)?;
        s.serialize_field("whats_this_help_id", &self.whats_this_help_id)?;
        s.serialize_field("width", &self.width)?;

        s.end()
    }
}

impl From<Properties> for DataProperties {
    fn from(prop: Properties) -> Self {
        let mut data_prop = DataProperties::default();

        data_prop.align = prop.get_property("Align", data_prop.align);
        data_prop.appearance = prop.get_property("Appearance", data_prop.appearance);
        data_prop.back_color = prop.get_color("BackColor", data_prop.back_color);
        data_prop.bof_action = prop.get_property("BOFAction", data_prop.bof_action);
        data_prop.caption = match prop.get("Caption") {
            Some(caption) => caption.clone(),
            None => data_prop.caption,
        };
        data_prop.connection = prop
            .get("Connection")
            .map_or(Ok(ConnectionType::Access), |v| v.as_str().try_into())
            .unwrap_or(ConnectionType::Access);
        data_prop.database_name = match prop.get("DatabaseName") {
            Some(database_name) => database_name.clone(),
            None => String::new(),
        };
        data_prop.default_cursor_type =
            prop.get_property("DefaultCursorType", data_prop.default_cursor_type);
        data_prop.default_type = prop.get_property("DefaultType", data_prop.default_type);

        // TODO: Implement DragIcon parsing
        // DragIcon

        data_prop.drag_mode = prop.get_property("DragMode", data_prop.drag_mode);
        data_prop.enabled = prop.get_property("Enabled", data_prop.enabled);
        data_prop.eof_action = prop.get_property("EOFAction", data_prop.eof_action);
        data_prop.exclusive = prop.get_bool("Exclusive", data_prop.exclusive);
        data_prop.fore_color = prop.get_color("ForeColor", data_prop.fore_color);
        data_prop.height = prop.get_i32("Height", data_prop.height);
        data_prop.left = prop.get_i32("Left", data_prop.left);
        data_prop.mouse_pointer = prop.get_property("MousePointer", data_prop.mouse_pointer);
        data_prop.negotiate = prop.get_bool("Negotiate", data_prop.negotiate);
        data_prop.ole_drop_mode = prop.get_property("OLEDropMode", data_prop.ole_drop_mode);
        data_prop.options = prop.get_i32("Options", data_prop.options);
        data_prop.read_only = prop.get_bool("ReadOnly", data_prop.read_only);
        data_prop.record_set_type = prop.get_property("RecordsetType", data_prop.record_set_type);
        data_prop.record_source = match prop.get("RecordSource") {
            Some(record_source) => record_source.into(),
            None => String::new(),
        };

        data_prop.right_to_left = prop.get_property("RightToLeft", data_prop.right_to_left);
        data_prop.tool_tip_text = match prop.get("ToolTipText") {
            Some(tool_tip_text) => tool_tip_text.into(),
            None => String::new(),
        };
        data_prop.top = prop.get_i32("Top", data_prop.top);
        data_prop.visible = prop.get_property("Visible", data_prop.visible);
        data_prop.whats_this_help_id =
            prop.get_i32("WhatsThisHelpID", data_prop.whats_this_help_id);
        data_prop.width = prop.get_i32("Width", data_prop.width);

        data_prop
    }
}

/// `BOFAction` is used to determine what action the ADODC takes when the BOF
/// property is true.
///
/// [Reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa245042(v=vs.60))
#[derive(
    Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum BOFAction {
    /// Keeps the first record as the current record.
    ///
    /// This is the default value.
    #[default]
    MoveFirst = 0,
    /// Moving past the start of a `RecordSet` triggers the `Validate` event on the
    /// first record, followed by a `Reposition` event on the invalid (BOF) record.
    /// At this point, the "Move Previous" button on the `Data` control is disabled.
    Bof = 1,
}

impl Display for BOFAction {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            BOFAction::MoveFirst => "MoveFirst",
            BOFAction::Bof => "BOF",
        };
        write!(f, "{text}")
    }
}

impl FromStr for BOFAction {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "0" => Ok(BOFAction::MoveFirst),
            "1" => Ok(BOFAction::Bof),
            _ => Err(ErrorKind::Form(FormError::InvalidBOFAction {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for BOFAction {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        BOFAction::from_str(value)
    }
}

/// Determine the type of connection to the ADODC database.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Default, Copy, Hash, PartialOrd, Ord)]
pub enum ConnectionType {
    /// The Data control is connecting to Microsoft Access database.
    ///
    /// This is the default value.
    #[default]
    Access,
    /// The Data control is connecting to `dBase III` database.
    DBaseIII,
    /// The Data control is connecting to `dBase IV` database.
    DBaseIV,
    /// The Data control is connecting to `dBase 5.0` database.
    DBase5_0,
    /// The Data control is connecting to `Excel 3.0` database.
    Excel3_0,
    /// The Data control is connecting to `Excel 4.0` database.
    Excel4_0,
    /// The Data control is connecting to `Excel 5.0` database.
    Excel5_0,
    /// The Data control is connecting to `Excel 8.0` database.
    Excel8_0,
    /// The Data control is connecting to `FoxPro 2.0` database.
    FoxPro2_0,
    /// The Data control is connecting to `FoxPro 2.5` database.
    FoxPro2_5,
    /// The Data control is connecting to `FoxPro 2.6` database.
    FoxPro2_6,
    /// The Data control is connecting to `FoxPro 3.0` database.
    FoxPro3_0,
    /// The Data control is connecting to `Lotus Works 1` database.
    LotusWk1,
    /// The Data control is connecting to `Lotus Works 3` database.
    LotusWk3,
    /// The Data control is connecting to `Lotus Works 4` database.
    LotusWk4,
    /// The Data control is connecting to `Paradox 3.X` database.
    Paradox3X,
    /// The Data control is connecting to `Paradox 4.X` database.
    Paradox4X,
    /// The Data control is connecting to `Paradox 5.X` database.
    Paradox5X,
    /// The Data control is connecting to a `Text` data set.
    Text,
}

impl Display for ConnectionType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            ConnectionType::Access => "Access",
            ConnectionType::DBaseIII => "dBase III",
            ConnectionType::DBaseIV => "dBase IV",
            ConnectionType::DBase5_0 => "dBase 5.0",
            ConnectionType::Excel3_0 => "Excel 3.0",
            ConnectionType::Excel4_0 => "Excel 4.0",
            ConnectionType::Excel5_0 => "Excel 5.0",
            ConnectionType::Excel8_0 => "Excel 8.0",
            ConnectionType::FoxPro2_0 => "FoxPro 2.0",
            ConnectionType::FoxPro2_5 => "FoxPro 2.5",
            ConnectionType::FoxPro2_6 => "FoxPro 2.6",
            ConnectionType::FoxPro3_0 => "FoxPro 3.0",
            ConnectionType::LotusWk1 => "Lotus WK1",
            ConnectionType::LotusWk3 => "Lotus WK3",
            ConnectionType::LotusWk4 => "Lotus WK4",
            ConnectionType::Paradox3X => "Paradox 3.X",
            ConnectionType::Paradox4X => "Paradox 4.X",
            ConnectionType::Paradox5X => "Paradox 5.X",
            ConnectionType::Text => "Text",
        };
        write!(f, "{text}")
    }
}

impl FromStr for ConnectionType {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Access" => Ok(ConnectionType::Access),
            "dBase III" => Ok(ConnectionType::DBaseIII),
            "dBase IV" => Ok(ConnectionType::DBaseIV),
            "dBase 5.0" => Ok(ConnectionType::DBase5_0),
            "Excel 3.0" => Ok(ConnectionType::Excel3_0),
            "Excel 4.0" => Ok(ConnectionType::Excel4_0),
            "Excel 5.0" => Ok(ConnectionType::Excel5_0),
            "Excel 8.0" => Ok(ConnectionType::Excel8_0),
            "FoxPro 2.0" => Ok(ConnectionType::FoxPro2_0),
            "FoxPro 2.5" => Ok(ConnectionType::FoxPro2_5),
            "FoxPro 2.6" => Ok(ConnectionType::FoxPro2_6),
            "FoxPro 3.0" => Ok(ConnectionType::FoxPro3_0),
            "Lotus WK1" => Ok(ConnectionType::LotusWk1),
            "Lotus WK3" => Ok(ConnectionType::LotusWk3),
            "Lotus WK4" => Ok(ConnectionType::LotusWk4),
            "Paradox 3.X" => Ok(ConnectionType::Paradox3X),
            "Paradox 4.X" => Ok(ConnectionType::Paradox4X),
            "Paradox 5.X" => Ok(ConnectionType::Paradox5X),
            "Text" => Ok(ConnectionType::Text),
            _ => Err(ErrorKind::Form(FormError::InvalidConnectionType {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for ConnectionType {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        ConnectionType::from_str(value)
    }
}

/// Controls what type of cursor driver is used on the connection (`ODBCDirect` only)
/// created by the `Data` control.
///
/// [Reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa234557(v=vs.60))
#[derive(
    Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum DefaultCursorType {
    /// Let the ODBC driver determine which type of cursor to use.
    ///
    /// This is the default value.
    #[default]
    Default = 0,
    /// Use the ODBC cursor library. This option gives better performance for
    /// small result sets, but degrades quickly for larger result sets.
    Odbc = 1,
    /// Use server side cursors. For most large operations this gives
    /// better performance, but might cause more network traffic.
    ServerSide = 2,
}

impl Display for DefaultCursorType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            DefaultCursorType::Default => "Default",
            DefaultCursorType::Odbc => "Odbc",
            DefaultCursorType::ServerSide => "ServerSide",
        };
        write!(f, "{text}")
    }
}

impl FromStr for DefaultCursorType {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "0" => Ok(DefaultCursorType::Default),
            "1" => Ok(DefaultCursorType::Odbc),
            "2" => Ok(DefaultCursorType::ServerSide),
            _ => Err(ErrorKind::Form(FormError::InvalidDefaultCursorType {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for DefaultCursorType {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        DefaultCursorType::from_str(value)
    }
}

/// Determines the type of data source (`Jet` or `ODBCDirect`) that is used by the
/// `Data` control.
///
/// [Reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa234568(v=vs.60))
#[derive(
    Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum DatabaseDriverType {
    /// Use the `ODBCDirect` driver to access the data source.
    UseODBC = 1,
    /// Use the `Microsoft Jet` database engine to access the data source.
    ///
    /// This is the default value.
    #[default]
    UseJet = 2,
}

impl Display for DatabaseDriverType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            DatabaseDriverType::UseODBC => "UseODBC",
            DatabaseDriverType::UseJet => "UseJet",
        };
        write!(f, "{text}")
    }
}

impl FromStr for DatabaseDriverType {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "1" => Ok(DatabaseDriverType::UseODBC),
            "2" => Ok(DatabaseDriverType::UseJet),
            _ => Err(ErrorKind::Form(FormError::InvalidDatabaseDriverType {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for DatabaseDriverType {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        DatabaseDriverType::from_str(value)
    }
}

/// Determines what actions to take within the `Data` control when the EOF
/// property is true.
///
/// [Reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa245042(v=vs.60))
#[derive(
    Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum EOFAction {
    /// Keep the last record as the current record.
    ///
    /// This is the default value.
    #[default]
    MoveLast = 0,
    /// Moving past the end of a `Recordset` triggers the `Data` control's
    /// `Validation` event on the last record, followed by a `Reposition` event
    /// on the invalid (EOF) record. At that point, the `MoveNext` button on the
    /// `Data` control is disabled.
    Eof = 1,
    /// Moving past the last record triggers the `Data` control's `Validation`
    /// event to occur on the current record, followed by an automatic `AddNew`,
    /// followed by a `Reposition` event on the new record.
    AddNew = 2,
}

impl Display for EOFAction {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            EOFAction::MoveLast => "MoveLast",
            EOFAction::Eof => "EOF",
            EOFAction::AddNew => "AddNew",
        };
        write!(f, "{text}")
    }
}

impl FromStr for EOFAction {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "0" => Ok(EOFAction::MoveLast),
            "1" => Ok(EOFAction::Eof),
            "2" => Ok(EOFAction::AddNew),
            _ => Err(ErrorKind::Form(FormError::InvalidEOFAction {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for EOFAction {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        EOFAction::from_str(value)
    }
}

/// Determines the type of `Recordset` object you want the `Data` control to
/// create.
///
/// [Reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa268103(v=vs.60))
#[derive(
    Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum RecordSetType {
    /// Use a `Table` type `Recordset` object.
    Table = 0,
    /// Use a `Dynaset` type `Recordset` object.
    ///
    /// This is the default value.
    #[default]
    Dynaset = 1,
    /// Use a `Snapshot` type `Recordset` object.
    Snapshot = 2,
}

impl Display for RecordSetType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let text = match self {
            RecordSetType::Table => "Table",
            RecordSetType::Dynaset => "Dynaset",
            RecordSetType::Snapshot => "Snapshot",
        };
        write!(f, "{text}")
    }
}

impl FromStr for RecordSetType {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "0" => Ok(RecordSetType::Table),
            "1" => Ok(RecordSetType::Dynaset),
            "2" => Ok(RecordSetType::Snapshot),
            _ => Err(ErrorKind::Form(FormError::InvalidRecordSetType {
                value: s.to_string(),
            })),
        }
    }
}

impl TryFrom<&str> for RecordSetType {
    type Error = ErrorKind;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        RecordSetType::from_str(value)
    }
}